1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add an error for $tmpl function type mismatches (#18826)

This commit is contained in:
Swastik Baranwal 2023-07-09 22:10:10 +05:30 committed by GitHub
parent 59eb76c81d
commit 0498f4c40f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 0 deletions

View File

@ -179,6 +179,11 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
c.error('cannot use `${c.table.type_to_str(got_type)}` as ${c.error_type_name(exp_type)} in return argument', c.error('cannot use `${c.table.type_to_str(got_type)}` as ${c.error_type_name(exp_type)} in return argument',
pos) pos)
} }
if exprv is ast.ComptimeCall && exprv.method_name == 'tmpl'
&& c.table.final_sym(exp_type).kind != .string {
c.error('cannot use `string` as type `${c.table.type_to_str(exp_type)}` in return argument',
exprv.pos)
}
if node.exprs[expr_idxs[i]] !is ast.ComptimeCall { if node.exprs[expr_idxs[i]] !is ast.ComptimeCall {
got_type_sym := c.table.sym(got_type) got_type_sym := c.table.sym(got_type)
exp_type_sym := c.table.sym(exp_type) exp_type_sym := c.table.sym(exp_type)

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/template_type_mismatch_err.vv:6:9: error: cannot use `string` as type `int` in return argument
4 |
5 | fn return_item() int {
6 | return $tmpl('./templates/template.md')
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 | }

View File

@ -0,0 +1,7 @@
fn main() {
println(return_item())
}
fn return_item() int {
return $tmpl('./templates/template.md')
}

View File

@ -0,0 +1 @@