Skip to content

fixes #25591; error with capture in closure iterator#25841

Draft
ringabout wants to merge 2 commits into
develfrom
pr_dsj
Draft

fixes #25591; error with capture in closure iterator#25841
ringabout wants to merge 2 commits into
develfrom
pr_dsj

Conversation

@ringabout
Copy link
Copy Markdown
Member

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:

  • Updated the detectCapturedVars procedure in compiler/lambdalifting.nim to 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:

Copilot AI review requested due to automatic review settings May 28, 2026 14:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 detectCapturedVars in compiler/lambdalifting.nim to explicitly traverse nkClosure nodes (following the closure’s environment operand).
  • Added a regression snippet to tests/iter/titer_issues.nim that 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.

@ringabout ringabout marked this pull request as draft May 28, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: internal error: inconsistent environment type with iterator use with capture in closure iterator

2 participants