Skip to content

fixes lent tuple codegen error#25782

Open
ringabout wants to merge 2 commits intodevelfrom
pr_re_uiu
Open

fixes lent tuple codegen error#25782
ringabout wants to merge 2 commits intodevelfrom
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.

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.

2 participants