-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
closure defined inside comptime $for uses first iterations value for every iteration #25513
Copy link
Copy link
Closed
Copy link
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.ComptimeFeatures processed during compile time, like $if, $for, $env etcFeatures processed during compile time, like $if, $for, $env etcStatus: ConfirmedThis bug has been confirmed to be valid by a contributor.This bug has been confirmed to be valid by a contributor.Unit: CompilerBugs/feature requests, that are related to the V compiler in general.Bugs/feature requests, that are related to the V compiler in general.Unit: cgenBugs/feature requests, that are related to the default C generating backend.Bugs/feature requests, that are related to the default C generating backend.
Description
Metadata
Metadata
Assignees
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.ComptimeFeatures processed during compile time, like $if, $for, $env etcFeatures processed during compile time, like $if, $for, $env etcStatus: ConfirmedThis bug has been confirmed to be valid by a contributor.This bug has been confirmed to be valid by a contributor.Unit: CompilerBugs/feature requests, that are related to the V compiler in general.Bugs/feature requests, that are related to the V compiler in general.Unit: cgenBugs/feature requests, that are related to the default C generating backend.Bugs/feature requests, that are related to the default C generating backend.
Type
Fields
Give feedbackNo fields configured for Bug.
Describe the bug
when you write a
$forloop over e.g. a structs fields and there is a closure definition which uses the field in its body it will always use the first field for every iterationReproduction Steps
a kinda stupid example just to keep it simple:
Expected Behavior
Current Behavior
Possible Solution
I inspected the generated c code, and I think the problem is that every iterations closure uses the same function. which is that of the first iteration (that updates the first field)
the closure defs:
both reference:
which updates field
aAdditional Information/Context
No response
V version
V 0.4.12 e5a5f02
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.