mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-15 11:29:25 +00:00
fixes #25469; Conversion from distinct in for forces a copy of underlying instance
This commit is contained in:
@@ -702,6 +702,11 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
|
||||
of nkAddr, nkHiddenAddr:
|
||||
result = putArgInto(arg[0], formal)
|
||||
if result == paViaIndirection: result = paFastAsgn
|
||||
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||
if compareTypes(arg.typ, arg[1].typ, dcEqIgnoreDistinct, {IgnoreRangeShallow}):
|
||||
result = putArgInto(arg[1], formal)
|
||||
else:
|
||||
result = paFastAsgn
|
||||
of nkCurly, nkBracket:
|
||||
for i in 0..<arg.len:
|
||||
if putArgInto(arg[i], formal) != paDirectMapping:
|
||||
|
||||
41
tests/arc/tdistinct_for_nodup.nim
Normal file
41
tests/arc/tdistinct_for_nodup.nim
Normal file
@@ -0,0 +1,41 @@
|
||||
discard """
|
||||
cmd: '''nim c --mm:arc --expandArc:foo $file'''
|
||||
nimout: '''
|
||||
--expandArc: foo
|
||||
|
||||
var broken_cursor
|
||||
block :tmp:
|
||||
var i
|
||||
var i_1 = 0
|
||||
let L = len(seq[Large](broken_cursor))
|
||||
block :tmp_1:
|
||||
while i_1 < L:
|
||||
i = seq[Large](broken_cursor)[i_1]
|
||||
discard i
|
||||
{.push, overflowChecks: false.}
|
||||
inc(i_1, 1)
|
||||
{.pop.}
|
||||
const
|
||||
loc`gensym1 = (filename: "iterators.nim", line: 254, column: 10)
|
||||
ploc`gensym1 = "iterators.nim(254, 11)"
|
||||
bind instantiationInfo
|
||||
mixin failedAssertImpl
|
||||
{.line: (filename: "iterators.nim", line: 254, column: 10).}:
|
||||
if not (len(seq[Large](broken_cursor)) == L):
|
||||
failedAssertImpl("iterators.nim(254, 11) `len(a) == L` the length of the seq changed while iterating over it")
|
||||
-- end of expandArc ------------------------
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
type
|
||||
Large = array[1024, byte]
|
||||
List = distinct seq[Large]
|
||||
|
||||
proc foo =
|
||||
var
|
||||
broken: List
|
||||
for i in seq[Large](broken):
|
||||
discard i
|
||||
|
||||
foo()
|
||||
Reference in New Issue
Block a user