summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2018-01-29 04:59:49 +0000
committerAndreas Rumpf <rumpf_a@web.de>2018-01-29 05:59:49 +0100
commit12b11fd848f68ce0543c6e0dc705b6d445e00146 (patch)
treeeefe6f27446175ad73642ff32ad4c8e587d49556
parentfcd4cd82c3ae4ab6872ad15e3e9116189f2de924 (diff)
downloadNim-12b11fd848f68ce0543c6e0dc705b6d445e00146.tar.gz
Fix compiler crash on try expression with infix as (Fixes #7116) (#7112)
* Fix compiler crash

* make sure type is not lost
-rw-r--r--compiler/transf.nim2
-rw-r--r--tests/exception/texcas.nim10
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 14ff58c90..94899c5d4 100644
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -716,7 +716,7 @@ proc transformExceptBranch(c: PTransf, n: PNode): PTransNode =
   result = transformSons(c, n)
   if n[0].isInfixAs():
     let excTypeNode = n[0][1]
-    let actions = newTransNode(nkStmtList, n[1].info, 2)
+    let actions = newTransNode(nkStmtListExpr, n[1], 2)
     # Generating `let exc = (excType)(getCurrentException())`
     # -> getCurrentException()
     let excCall = PTransNode(callCodegenProc("getCurrentException", ast.emptyNode))
diff --git a/tests/exception/texcas.nim b/tests/exception/texcas.nim
index 4b4ebe448..fee45af3f 100644
--- a/tests/exception/texcas.nim
+++ b/tests/exception/texcas.nim
@@ -21,5 +21,13 @@ proc test2() =
   testTemplate(Exception)
   doAssert(not declared(foobar))
 
+
+proc testTryAsExpr(i: int) =
+  let x = try: i    
+  except ValueError as ex:
+    echo(ex.msg)
+    -1
+
 test[Exception]()
-test2()
\ No newline at end of file
+test2()
+testTryAsExpr(5)