diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-08-08 15:34:21 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-08 15:34:21 +0200 |
commit | 32b62097a2636c5053d842939d34e2a0fa3f9e33 (patch) | |
tree | 8198bc2b8ac193b482b2543fe627cdd5df110258 /lib | |
parent | af4f4425e2d461f7b2b6ec88cf60816f671fa435 (diff) | |
download | Nim-32b62097a2636c5053d842939d34e2a0fa3f9e33.tar.gz |
Fix regression for mapIt (#8567)
Don't try to be too smart and limit the use of `evalOnce` where strictly needed as not every value can be assigned with a `let`. Fixes #8566
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/collections/sequtils.nim | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 8f81fe4f5..99ce91979 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -676,8 +676,8 @@ template mapIt*(s, op: untyped): untyped = var it{.inject.}: type(items(s)); op)) var result: seq[outType] - evalOnce(t, s) - when compiles(t.len): + when compiles(s.len): + evalOnce(t, s) var i = 0 result = newSeq[outType](t.len) for it {.inject.} in t: @@ -685,7 +685,7 @@ template mapIt*(s, op: untyped): untyped = i += 1 else: result = @[] - for it {.inject.} in t: + for it {.inject.} in s: result.add(op) result @@ -1071,5 +1071,10 @@ when isMainModule: proc foo(x: openArray[int]): seq[int] = x.mapIt(it + 1) doAssert foo([1,2,3]) == @[2,3,4] + block: # mapIt with invalid RHS for `let` (#8566) + type X = enum + A, B + doAssert mapIt(X, $it) == @["A", "B"] + when not defined(testing): echo "Finished doc tests" |