summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2018-09-07 01:56:36 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-09-07 01:56:36 +0200
commit84eab97fed35651234da14d188962bb8045b5b1e (patch)
treec6bcc9b144559363b7bbe902715def1c398f485c
parentaf1e84f54da32b5e8e917edc533c6efa6846acc2 (diff)
downloadNim-84eab97fed35651234da14d188962bb8045b5b1e.tar.gz
Sync line generation between C and JS backends (#8888)
Fixes #7224
-rw-r--r--compiler/jsgen.nim6
-rw-r--r--tests/js/t7224.nim26
2 files changed, 29 insertions, 3 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index da35002b7..0fc21b2d1 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -658,15 +658,16 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
   line(p, "}\L")
 
 proc genRaiseStmt(p: PProc, n: PNode) =
-  genLineDir(p, n)
   if n.sons[0].kind != nkEmpty:
     var a: TCompRes
     gen(p, n.sons[0], a)
     let typ = skipTypes(n.sons[0].typ, abstractPtrs)
+    genLineDir(p, n)
     useMagic(p, "raiseException")
     lineF(p, "raiseException($1, $2);$n",
              [a.rdLoc, makeJSString(typ.sym.name.s)])
   else:
+    genLineDir(p, n)
     useMagic(p, "reraiseException")
     line(p, "reraiseException();\L")
 
@@ -856,6 +857,7 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
   else:
     gen(p, x, a)
 
+  genLineDir(p, y)
   gen(p, y, b)
 
   # we don't care if it's an etyBaseIndex (global) of a string, it's
@@ -892,11 +894,9 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
     lineF(p, "$1 = $2;$n", [a.res, b.res])
 
 proc genAsgn(p: PProc, n: PNode) =
-  genLineDir(p, n)
   genAsgnAux(p, n.sons[0], n.sons[1], noCopyNeeded=false)
 
 proc genFastAsgn(p: PProc, n: PNode) =
-  genLineDir(p, n)
   # 'shallowCopy' always produced 'noCopyNeeded = true' here but this is wrong
   # for code like
   #  while j >= pos:
diff --git a/tests/js/t7224.nim b/tests/js/t7224.nim
new file mode 100644
index 000000000..2d7ee1336
--- /dev/null
+++ b/tests/js/t7224.nim
@@ -0,0 +1,26 @@
+discard """
+  cmd: "nim $target $options --stackTrace:on --lineTrace:on $file"
+  outputsub: '''
+t7224.aaa, line: 21
+t7224.bbb, line: 18
+t7224.ccc, line: 15
+t7224.ddd, line: 12
+'''
+"""
+  
+proc ddd() =
+  raise newException(IOError, "didn't do stuff")
+
+proc ccc() =
+  ddd()
+
+proc bbb() =
+  ccc()
+
+proc aaa() =
+  bbb()
+
+try:
+  aaa()
+except IOError as e:
+  echo getStackTrace(e)