cgen: fix comptime for_in methods call using str_intp (#12746)

pull/12756/head
yuyi 2021-12-07 17:12:12 +08:00 committed by GitHub
parent 1cb06a2de4
commit f60cf65284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -126,7 +126,7 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int) {
typ := g.unwrap_generic(node.expr_types[i])
typ_sym := g.table.get_type_symbol(typ)
if typ == ast.string_type {
if typ == ast.string_type && g.comptime_for_method.len == 0 {
if g.inside_vweb_tmpl {
g.write('vweb__filter(')
if expr.is_auto_deref_var() {
@ -153,7 +153,7 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int) {
mut exp_typ := typ
if expr is ast.Ident {
if expr.obj is ast.Var {
if g.comptime_var_type_map.len > 0 {
if g.comptime_var_type_map.len > 0 || g.comptime_for_method.len > 0 {
exp_typ = expr.obj.typ
} else if expr.obj.smartcasts.len > 0 {
cast_sym := g.table.get_type_symbol(expr.obj.smartcasts.last())

View File

@ -14,10 +14,17 @@ fn test_comptime_for_method_call() {
$for method in Foo.methods {
x := f.$method()
println(x)
println(x.str())
println('$x')
rets << x.str()
rets << '$x'
}
assert rets.len == 2
assert rets.len == 4
assert rets[0] == '1'
assert rets[1] == '2'
assert rets[1] == '1'
assert rets[2] == '2'
assert rets[3] == '2'
}