checker: fix goto label with comptime tmpl (#12853)

pull/12859/head
yuyi 2021-12-16 00:48:43 +08:00 committed by GitHub
parent 2b981b011e
commit c44115c67d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -30,6 +30,7 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
}
if node.is_vweb {
// TODO assoc parser bug
save_cur_fn := c.table.cur_fn
pref_ := *c.pref
pref2 := &pref.Preferences{
...pref_
@ -56,6 +57,8 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
c.nr_warnings += c2.nr_warnings
c.nr_errors += c2.nr_errors
c.nr_notices += c2.nr_notices
c.table.cur_fn = save_cur_fn
}
if node.method_name == 'html' {
rtyp := c.table.find_type_idx('vweb.Result')

View File

@ -36,3 +36,19 @@ pub fn test_goto_after_return() {
finally_ok:
assert true
}
fn test_goto_with_comptime_tmpl() {
a := 22
_ := $tmpl('./tmpl/a.txt')
println('before goto')
unsafe {
goto label
}
println('failed goto')
assert false
label:
println('goto label')
assert true
}