mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-29 08:15:14 +00:00
ref https://github.com/nim-lang/Nim/pull/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 f2e4ae0016)
13 lines
175 B
Nim
13 lines
175 B
Nim
discard """
|
|
errormsg: "expression has no address"
|
|
"""
|
|
|
|
iterator foo(x: int): (lent int, lent int) =
|
|
yield (x, x + 1)
|
|
|
|
|
|
var x = 12
|
|
for i in foo(x):
|
|
echo i[0]
|
|
echo i[1]
|