From 152d97b868c20100f83f428d256893b1eca404a5 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 30 Dec 2024 14:46:54 -0300 Subject: [PATCH 1/2] fix --- vlib/v/checker/for.v | 2 ++ .../skip_unused/generic_iterator_loop.run.out | 0 .../generic_iterator_loop.skip_unused.run.out | 0 .../skip_unused/generic_iterator_loop.vv | 32 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 vlib/v/tests/skip_unused/generic_iterator_loop.run.out create mode 100644 vlib/v/tests/skip_unused/generic_iterator_loop.skip_unused.run.out create mode 100644 vlib/v/tests/skip_unused/generic_iterator_loop.vv diff --git a/vlib/v/checker/for.v b/vlib/v/checker/for.v index 6e1dc735636a61..9ef3e116b3a492 100644 --- a/vlib/v/checker/for.v +++ b/vlib/v/checker/for.v @@ -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 } diff --git a/vlib/v/tests/skip_unused/generic_iterator_loop.run.out b/vlib/v/tests/skip_unused/generic_iterator_loop.run.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/vlib/v/tests/skip_unused/generic_iterator_loop.skip_unused.run.out b/vlib/v/tests/skip_unused/generic_iterator_loop.skip_unused.run.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/vlib/v/tests/skip_unused/generic_iterator_loop.vv b/vlib/v/tests/skip_unused/generic_iterator_loop.vv new file mode 100644 index 00000000000000..7d0bdf5de5e6d4 --- /dev/null +++ b/vlib/v/tests/skip_unused/generic_iterator_loop.vv @@ -0,0 +1,32 @@ +module main + +interface IFoo { + next() ?Foo +} + +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 loop2(iter IFoo) { + for _ in iter { + } +} + +fn main() { + loop(Foo{}) + loop(Bar{}) +} From b57bca7a55484735e09f299d01f0c3d5272ce03f Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 30 Dec 2024 16:29:36 -0300 Subject: [PATCH 2/2] cleanup --- vlib/v/tests/skip_unused/generic_iterator_loop.vv | 9 --------- 1 file changed, 9 deletions(-) diff --git a/vlib/v/tests/skip_unused/generic_iterator_loop.vv b/vlib/v/tests/skip_unused/generic_iterator_loop.vv index 7d0bdf5de5e6d4..b34e36d70d0843 100644 --- a/vlib/v/tests/skip_unused/generic_iterator_loop.vv +++ b/vlib/v/tests/skip_unused/generic_iterator_loop.vv @@ -1,9 +1,5 @@ module main -interface IFoo { - next() ?Foo -} - struct Foo {} fn (f Foo) next() ?Foo { @@ -21,11 +17,6 @@ fn loop[T](iter T) { } } -fn loop2(iter IFoo) { - for _ in iter { - } -} - fn main() { loop(Foo{}) loop(Bar{})