checker: fix error for marking as referenced (#13859)

pull/13865/head
yuyi 2022-03-30 06:33:10 +08:00 committed by GitHub
parent 42a67831bf
commit 55d9464890
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -3556,6 +3556,9 @@ pub fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool)
if c.fn_scope != voidptr(0) {
obj = c.fn_scope.find_var(node.obj.name) or { obj }
}
if obj.typ == 0 {
return
}
type_sym := c.table.sym(obj.typ.set_nr_muls(0))
if obj.is_stack_obj && !type_sym.is_heap() && !c.pref.translated
&& !c.file.is_translated {

View File

@ -0,0 +1,24 @@
module main
fn test_mark_as_referenced() {
if true {
a := Type{}
ret := f(a)
println(ret)
assert ret == 'Interface(Type{})'
}
a := Type{}
ret := f(a)
println(ret)
assert ret == 'Interface(Type{})'
}
struct Type {
}
interface Interface {
}
fn f(b Interface) string {
return '$b'
}