summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-01-25 09:34:45 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-01-25 09:34:51 +0100
commit1fa3a9dac25e982624164898d98f22565c16d566 (patch)
tree4cbcf4b3f843b34a767abf1e0a2305363f2893d4
parentc7e54eba91e31091a40dfa6d96a7a323db63b933 (diff)
downloadNim-1fa3a9dac25e982624164898d98f22565c16d566.tar.gz
bugfix: inline iterator do not mess up line information anymore
-rw-r--r--compiler/transf.nim10
-rw-r--r--tests/errmsgs/tproper_stacktrace2.nim22
2 files changed, 29 insertions, 3 deletions
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 4208c43e5..6eed17b2a 100644
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -133,13 +133,17 @@ proc transformSymAux(c: PTransf, n: PNode): PNode =
     # simply exchange the symbol:
     b = s.getBody
     if b.kind != nkSym: internalError(n.info, "wrong AST for borrowed symbol")
-    b = newSymNode(b.sym)
-    b.info = n.info
+    b = newSymNode(b.sym, n.info)
   else:
     b = n
   while tc != nil:
     result = idNodeTableGet(tc.mapping, b.sym)
-    if result != nil: return
+    if result != nil:
+      # this slightly convoluted way ensures the line info stays correct:
+      if result.kind == nkSym:
+        result = copyNode(result)
+        result.info = n.info
+      return
     tc = tc.next
   result = b
 
diff --git a/tests/errmsgs/tproper_stacktrace2.nim b/tests/errmsgs/tproper_stacktrace2.nim
new file mode 100644
index 000000000..5f312b870
--- /dev/null
+++ b/tests/errmsgs/tproper_stacktrace2.nim
@@ -0,0 +1,22 @@
+discard """
+  outputsub: '''tproper_stacktrace2.nim(20) main'''
+  exitcode: 1
+"""
+
+proc returnsNil(): string = return nil
+
+iterator fields*(a, b: int): int =
+  if a == b:
+    for f in a..b:
+      yield f
+  else:
+    for f in a..b:
+      yield f
+
+proc main(): string =
+  result = ""
+  for i in fields(0, 1):
+    let x = returnsNil()
+    result &= "string literal " & $x
+
+echo main()