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:
parent
59eb76c81d
commit
0498f4c40f
@ -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',
|
||||
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 {
|
||||
got_type_sym := c.table.sym(got_type)
|
||||
exp_type_sym := c.table.sym(exp_type)
|
||||
|
6
vlib/v/checker/tests/template_type_mismatch_err.out
Normal file
6
vlib/v/checker/tests/template_type_mismatch_err.out
Normal 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 | }
|
7
vlib/v/checker/tests/template_type_mismatch_err.vv
Normal file
7
vlib/v/checker/tests/template_type_mismatch_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
println(return_item())
|
||||
}
|
||||
|
||||
fn return_item() int {
|
||||
return $tmpl('./templates/template.md')
|
||||
}
|
1
vlib/v/checker/tests/templates/template.md
Normal file
1
vlib/v/checker/tests/templates/template.md
Normal file
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user