mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #24274
The code in the `if` branch replaces the current destination `d` with a
new one. But the location `d` can be an assignment location, in which
case the provided expression isn't generated. To fix this, don't trigger
this code for when the location already exists. An alternative would be
to call `putIntoDest` in this case as is done below.
(cherry picked from commit 9c85f4fd07)
22 lines
393 B
Nim
22 lines
393 B
Nim
discard """
|
|
targets: "c cpp"
|
|
"""
|
|
|
|
block: # issue #24274
|
|
iterator foo[T](x: var T): var T =
|
|
yield x
|
|
|
|
var x: array[3, char]
|
|
for a in foo(x):
|
|
let b = a
|
|
|
|
var y: array[3, char] = ['a', 'b', 'c']
|
|
for a in foo(y):
|
|
let b = a
|
|
doAssert a[0] == 'a'
|
|
doAssert a[1] == 'b'
|
|
doAssert a[2] == 'c'
|
|
doAssert b[0] == 'a'
|
|
doAssert b[1] == 'b'
|
|
doAssert b[2] == 'c'
|