checker: fix checking for int to array of interface (fix #24624) (#24625)

This commit is contained in:
Felipe Pena 2025-06-01 00:14:33 -03:00 committed by GitHub
parent 8b5ee60275
commit 056998a42a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -4694,8 +4694,8 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) {
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 {
if obj.is_stack_obj && !type_sym.is_heap() && !type_sym.is_int()
&& !c.pref.translated && !c.file.is_translated {
suggestion := if type_sym.kind == .struct {
'declaring `${type_sym.name}` as `@[heap]`'
} else {

View File

@ -0,0 +1,12 @@
module main
interface Value {}
fn test_main() {
mut a := []string{len: 10}
mut v := []Value{}
for i := 0; i < a.len; i++ {
v << i
}
assert v[0] == Value(0)
}