Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a compiler internal error (issue #25591) involving captured variables inside a closure used within an iterator, by adjusting lambda-lifting captured-variable detection and adding a regression test to ensure the pattern compiles.
Changes:
- Updated
detectCapturedVarsincompiler/lambdalifting.nimto explicitly traversenkClosurenodes (following the closure’s environment operand). - Added a regression snippet to
tests/iter/titer_issues.nimthat reproduces the reported “inconsistent environment type” internal error and verifies the fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| compiler/lambdalifting.nim | Ensures captured-variable detection visits closure environment nodes (nkClosure) during lambda lifting. |
| tests/iter/titer_issues.nim | Adds a regression block reproducing issue #25591 with iterators + closures capturing locals. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #25591
This pull request makes targeted improvements to the compiler's lambda lifting logic and adds a new test case to cover a previously reported bug involving object iterators and closures. The most significant changes are an enhancement to how closure nodes are handled during captured variable detection and the addition of a regression test for bug #25591.
Compiler improvements:
detectCapturedVarsprocedure incompiler/lambdalifting.nimto ensure that closure nodes (nkClosure) are properly traversed for captured variable detection, which helps with correct lambda lifting and closure analysis.Testing and bug coverage:
tests/iter/titer_issues.nimto reproduce and verify the fix for bugError: internal error: inconsistent environment typewith iterator use with capture in closure iterator #25591, involving iterators that capture variables via closures. This ensures that the compiler correctly handles this edge case in user code.