cgen: fix error for empty interface

pull/13764/head
yuyi98 2022-03-18 11:01:01 +08:00
parent 136f39a2d4
commit 2591ed2ea2
2 changed files with 15 additions and 1 deletions

View File

@ -507,7 +507,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
else { ast.Type(0) }
}
sub_sym := g.table.sym(sub_type)
g.write('_${c_name(sym.name)}_${c_name(sub_sym.name)}_index')
g.write('_${sym.cname}_${sub_sym.cname}_index')
return
} else if sym.kind == .sum_type {
g.write('_typ $cmp_op ')

View File

@ -0,0 +1,14 @@
interface Any {}
fn print_out(x Any) string {
if x is string {
println(x)
return '$x'
}
return ''
}
fn test_empty_interface() {
ret := print_out('12345')
assert ret == '&12345'
}