* see whether it breaks

* fix #16884

* correct

* fix #14574
This commit is contained in:
flywind 2021-02-01 06:31:04 -06:00 • committed by GitHub
commit de4f2604c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View file

@ -1077,10 +1077,10 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
# supports proc getF(): var T # supports proc getF(): var T
if x.kind in {nkHiddenDeref, nkDerefExpr} and x[0].kind in nkCallKinds: if x.kind in {nkHiddenDeref, nkDerefExpr} and x[0].kind in nkCallKinds:
lineF(p, "nimCopy($1, $2, $3);$n", lineF(p, "nimCopy($1, $2, $3);$n",
[a.res, b.res, genTypeInfo(p, y.typ)]) [a.res, b.res, genTypeInfo(p, x.typ)])
else: else:
lineF(p, "$1 = nimCopy($1, $2, $3);$n", lineF(p, "$1 = nimCopy($1, $2, $3);$n",
[a.res, b.res, genTypeInfo(p, y.typ)]) [a.res, b.res, genTypeInfo(p, x.typ)])
of etyBaseIndex: of etyBaseIndex:
if a.typ != etyBaseIndex or b.typ != etyBaseIndex: if a.typ != etyBaseIndex or b.typ != etyBaseIndex:
if y.kind == nkCall: if y.kind == nkCall:

29
tests/js/t16822.nim Normal file
View file

@ -0,0 +1,29 @@
block: # bug #16822
var scores: seq[(set[char], int)] = @{{'/'} : 10}
var x1: set[char]
for item in items(scores):
x1 = item[0]
doAssert x1 == {'/'}
var x2: set[char]
for (chars, value) in items(scores):
x2 = chars
doAssert x2 == {'/'}
block: # bug #14574
proc fn(): auto =
let a = @[("foo", (12, 13))]
for (k,v) in a:
return (k,v)
doAssert fn() == ("foo", (12, 13))
block: # bug #14574
iterator fn[T](a:T): lent T = yield a
let a = (10, (11,))
proc bar(): auto =
for (x,y) in fn(a):
return (x,y)
doAssert bar() == (10, (11,))

View file

@ -42,7 +42,6 @@ template fn() =
block: block:
testRoundtrip({"z": "Z", "y": "Y"}.toOrderedTable): """{"z":"Z","y":"Y"}""" testRoundtrip({"z": "Z", "y": "Y"}.toOrderedTable): """{"z":"Z","y":"Y"}"""
when not defined(js): # pending https://github.com/nim-lang/Nim/issues/14574
testRoundtrip({"z": (f1: 'f'), }.toTable): """{"z":{"f1":102}}""" testRoundtrip({"z": (f1: 'f'), }.toTable): """{"z":{"f1":102}}"""
block: block: