summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-02-03 19:50:22 +0100
committerDominik Picheta <dominikpicheta@gmail.com>2017-02-03 19:50:22 +0100
commit1c233ba27a17830e325822fc27a12074eef49ccb (patch)
tree7314edbdedc47ffbf9efe3d3215af08ebf289ba7
parent656da1f6a99c504eb5bf7c51b01b8fe00e2afd71 (diff)
downloadNim-1c233ba27a17830e325822fc27a12074eef49ccb.tar.gz
More progress towards a working #3691.
-rw-r--r--compiler/lookups.nim2
-rw-r--r--compiler/semgnrc.nim10
-rw-r--r--compiler/semstmts.nim2
-rw-r--r--compiler/transf.nim2
-rw-r--r--tests/exception/texcas.nim17
5 files changed, 23 insertions, 10 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index cb7985384..19a4da07b 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -435,5 +435,5 @@ proc pickSym*(c: PContext, n: PNode; kind: TSymKind;
       return a
     a = nextOverloadIter(o, c, n)
 
-proc isExceptAs*(n: PNode): bool =
+proc isInfixAs*(n: PNode): bool =
   return n.kind == nkInfix and considerQuotedIdent(n[0]).s == "as"
\ No newline at end of file
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim
index 42f9bd401..bc80c41ad 100644
--- a/compiler/semgnrc.nim
+++ b/compiler/semgnrc.nim
@@ -338,17 +338,15 @@ proc semGenericStmt(c: PContext, n: PNode,
       var a = n.sons[i]
       checkMinSonsLen(a, 1)
       var L = sonsLen(a)
+      openScope(c)
       for j in countup(0, L-2):
-        debug(a.sons[j])
-        if a.sons[j].isExceptAs():
-          openScope(c)
+        if a.sons[j].isInfixAs():
           addTempDecl(c, getIdentNode(a.sons[j][2]), skLet)
-          a.sons[j] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx)
-          closeScope(c)
+          a.sons[j].sons[1] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx)
         else:
           a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc}, ctx)
-      debug(a)
       a.sons[L-1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx)
+      closeScope(c)
 
   of nkVarSection, nkLetSection:
     for i in countup(0, sonsLen(n) - 1):
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 674589306..9752ccac1 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -286,7 +286,7 @@ proc semTry(c: PContext, n: PNode): PNode =
         var typeNode = a.sons[j] # e.g. `Exception`
         var symbolNode: PNode = nil # e.g. `foobar`
         # Handle the case where the `Exception as foobar` syntax is used.
-        if typeNode.isExceptAs():
+        if typeNode.isInfixAs():
           typeNode = a.sons[j].sons[1]
           symbolNode = a.sons[j].sons[2]
 
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 838b2d902..13c6dd8fe 100644
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -703,7 +703,7 @@ proc transformCall(c: PTransf, n: PNode): PTransNode =
 
 proc transformExceptBranch(c: PTransf, n: PNode): PTransNode =
   result = transformSons(c, n)
-  if n[0].isExceptAs():
+  if n[0].isInfixAs():
     let excTypeNode = n[0][1]
     let actions = newTransNode(nkStmtList, n[1].info, 2)
     # Generating `let exc = (excType)(getCurrentException())`
diff --git a/tests/exception/texcas.nim b/tests/exception/texcas.nim
index 807f2c802..a00b09a8f 100644
--- a/tests/exception/texcas.nim
+++ b/tests/exception/texcas.nim
@@ -1,10 +1,25 @@
 discard """
-  output: '''Hello'''
+  output: '''Hello
+  Hello
+  '''
 """
 proc test[T]() =
   try:
     raise newException(T, "Hello")
   except T as foobar:
     echo(foobar.msg)
+  echo(declared(foobar))
+  doAssert(not declared(foobar))
+
+template testTemplate() =
+  try:
+    raise newException(Exception, "Hello")
+  except Exception as foobar:
+    echo(foobar.msg)
+  doAssert(not declared(foobar))
+
+proc test2() =
+  testTemplate()
+  doAssert(not declared(foobar))
 
 test[Exception]()