Skip to content

Commit

Permalink
checker: fix for iterator method .next(), not marked as used (fix v…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Dec 30, 2024
1 parent 17812a7 commit ab707dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vlib/v/checker/for.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions vlib/v/tests/skip_unused/generic_iterator_loop.vv
Original file line number Diff line number Diff line change
@@ -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{})
}

0 comments on commit ab707dc

Please sign in to comment.