mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix error for marking as referenced (#13859)
This commit is contained in:
parent
42a67831bf
commit
55d9464890
@ -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 {
|
||||
|
24
vlib/v/tests/mark_as_referenced_test.v
Normal file
24
vlib/v/tests/mark_as_referenced_test.v
Normal 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'
|
||||
}
|
Loading…
Reference in New Issue
Block a user