summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndy Davidoff <disruptek@users.noreply.github.com>2020-09-07 14:04:07 -0400
committerGitHub <noreply@github.com>2020-09-07 20:04:07 +0200
commit0b74d26d0c45e0fe16126bd264072783afacd12a (patch)
tree5c668e3cda232601ccaa0cb088c9d4753357b0c6 /compiler
parente08b802d79e173d230b893ed96fd82c3c5228161 (diff)
downloadNim-0b74d26d0c45e0fe16126bd264072783afacd12a.tar.gz
don't raise index defects on malformed ast (#15278)
* don't raise index defects on malformed ast

* style
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semcall.nim11
-rw-r--r--compiler/semstmts.nim9
2 files changed, 14 insertions, 6 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index 1a6f754ee..3e4ed096b 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -495,9 +495,14 @@ proc updateDefaultParams(call: PNode) =
 proc getCallLineInfo(n: PNode): TLineInfo =
   case n.kind
   of nkAccQuoted, nkBracketExpr, nkCall, nkCallStrLit, nkCommand:
-    getCallLineInfo(n[0])
-  of nkDotExpr: getCallLineInfo(n[1])
-  else: n.info
+    if len(n) > 0:
+      return getCallLineInfo(n[0])
+  of nkDotExpr:
+    if len(n) > 1:
+      return getCallLineInfo(n[1])
+  else:
+    discard
+  result = n.info
 
 proc semResolvedCall(c: PContext, x: TCandidate,
                      n: PNode, flags: TExprFlags): PNode =
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index fd4635ea5..5599eb3ef 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -324,11 +324,14 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
   proc getLineInfo(n: PNode): TLineInfo =
     case n.kind
     of nkPostfix:
-      getLineInfo(n[1])
+      if len(n) > 1:
+        return getLineInfo(n[1])
     of nkAccQuoted, nkPragmaExpr:
-      getLineInfo(n[0])
+      if len(n) > 0:
+        return getLineInfo(n[0])
     else:
-      n.info
+      discard
+    result = n.info
   let info = getLineInfo(n)
   suggestSym(c.config, info, result, c.graph.usageSym)