checker: fix for iterator method .next(), not marked as used (fix #23312) (#23321)

This commit is contained in:
Felipe Pena 2024-12-30 19:26:39 -03:00 committed by GitHub
parent 17812a77b8
commit ab707dce5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 0 deletions

View File

@ -173,6 +173,8 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
unwrapped_typ := c.unwrap_generic(typ)
unwrapped_sym := c.table.sym(unwrapped_typ)
c.table.used_features.comptime_calls['${int(unwrapped_typ)}.next'] = true
if node.key_var.len > 0 {
key_type := match unwrapped_sym.kind {
.map { unwrapped_sym.map_info().key_type }

View File

@ -0,0 +1,23 @@
module main
struct Foo {}
fn (f Foo) next() ?Foo {
return none
}
struct Bar {}
fn (f Bar) next() ?Bar {
return none
}
fn loop[T](iter T) {
for _ in iter {
}
}
fn main() {
loop(Foo{})
loop(Bar{})
}