Skip to content

fixes lent tuple codegen error#25782

Merged
Araq merged 2 commits into
develfrom
pr_re_uiu
May 6, 2026
Merged

fixes lent tuple codegen error#25782
Araq merged 2 commits into
develfrom
pr_re_uiu

Conversation

@ringabout
Copy link
Copy Markdown
Member

@ringabout ringabout commented Apr 30, 2026

ref #25783

This pull request addresses an issue with addressability of tuple elements of type lent or var in Nim, ensuring that expressions involving these types are handled correctly during type changes. The main changes introduce a check to prevent attempting to change the type of tuple elements that are views (var or lent), and a new test is added to verify the correct error is raised when trying to take the address of such elements.

Type system and semantic analysis improvements:

  • Added the isViewTarget template in semexprs.nim to check if a type is a view (var or lent), and updated changeType to skip type changes for tuple elements that are views. This prevents invalid addressability operations on these types. [1] [2]

Testing:

  • Added a new test tlent_tuple_address.nim to verify that attempting to take the address of tuple elements of type lent correctly produces an "expression has no address" error.

Copilot AI review requested due to automatic review settings April 30, 2026 13:22
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 PR addresses a semantic typing issue around tuple constructors when the expected tuple element types are view types (var/lent), which could lead to incorrect typing and downstream failures (notably for (lent T, lent T) scenarios referenced in #24723).

Changes:

  • Update changeType to avoid rewriting tuple-constructor element node types when the target element type is var/lent.
  • Add a regression test ensuring tuple yields requiring lent elements still correctly error when an element has no address.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/lent/tlent_tuple_address.nim Adds a regression test for tuple yields with lent elements that should fail due to an unaddressable expression.
compiler/semexprs.nim Prevents changeType from force-typing tuple elements to var/lent, avoiding incorrect view-typing of non-addressable expressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ringabout ringabout marked this pull request as draft May 5, 2026 11:25
@ringabout ringabout marked this pull request as ready for review May 5, 2026 11:25
@Araq Araq merged commit f2e4ae0 into devel May 6, 2026
21 checks passed
@Araq Araq deleted the pr_re_uiu branch May 6, 2026 06:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from f2e4ae0

Hint: mm: orc; opt: speed; options: -d:release
192297 lines; 9.402s; 802.047MiB peakmem

narimiran pushed a commit that referenced this pull request May 8, 2026
ref #25783

This pull request addresses an issue with addressability of tuple
elements of type `lent` or `var` in Nim, ensuring that expressions
involving these types are handled correctly during type changes. The
main changes introduce a check to prevent attempting to change the type
of tuple elements that are views (`var` or `lent`), and a new test is
added to verify the correct error is raised when trying to take the
address of such elements.

Type system and semantic analysis improvements:

* Added the `isViewTarget` template in `semexprs.nim` to check if a type
is a view (`var` or `lent`), and updated `changeType` to skip type
changes for tuple elements that are views. This prevents invalid
addressability operations on these types.
[[1]](diffhunk://#diff-539da3a63df08fa987f1b0c67d26cdc690753843d110b6bf0805a685eeaffd40R655-R657)
[[2]](diffhunk://#diff-539da3a63df08fa987f1b0c67d26cdc690753843d110b6bf0805a685eeaffd40R686-R693)

Testing:

* Added a new test `tlent_tuple_address.nim` to verify that attempting
to take the address of tuple elements of type `lent` correctly produces
an "expression has no address" error.

(cherry picked from commit f2e4ae0)
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.

3 participants