diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/guards.nim | 3 | ||||
-rw-r--r-- | compiler/sem.nim | 20 | ||||
-rw-r--r-- | compiler/semexprs.nim | 7 |
3 files changed, 18 insertions, 12 deletions
diff --git a/compiler/guards.nim b/compiler/guards.nim index d8441c544..8d271fa6d 100644 --- a/compiler/guards.nim +++ b/compiler/guards.nim @@ -187,7 +187,8 @@ proc usefulFact(n: PNode): PNode = # if a: # ... # We make can easily replace 'a' by '2 < x' here: - result = usefulFact(n.sym.ast) + if n.sym.ast != nil: + result = usefulFact(n.sym.ast) elif n.kind == nkStmtListExpr: result = usefulFact(n.lastSon) diff --git a/compiler/sem.nim b/compiler/sem.nim index bcdfc7939..4396a9093 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -141,22 +141,24 @@ proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode proc semWhen(c: PContext, n: PNode, semCheck: bool = true): PNode -proc evalTypedExpr(c: PContext, e: PNode): PNode = +proc semConstExpr(c: PContext, n: PNode): PNode = + var e = semExprWithType(c, n) + if e == nil: + LocalError(n.info, errConstExprExpected) + return n result = getConstExpr(c.module, e) if result == nil: result = evalConstExpr(c.module, e) if result == nil or result.kind == nkEmpty: - LocalError(e.info, errConstExprExpected) + if e.info != n.info: + pushInfoContext(n.info) + LocalError(e.info, errConstExprExpected) + popInfoContext() + else: + LocalError(e.info, errConstExprExpected) # error correction: result = e -proc semConstExpr(c: PContext, n: PNode): PNode = - var e = semExprWithType(c, n) - if e == nil: - LocalError(n.info, errConstExprExpected) - return n - result = evalTypedExpr(c, e) - include hlo, seminst, semcall proc symFromType(t: PType, info: TLineInfo): PSym = diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 28ea50a15..a524e71da 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -751,8 +751,11 @@ proc semEcho(c: PContext, n: PNode): PNode = checkMinSonsLen(n, 1) for i in countup(1, sonsLen(n) - 1): var arg = semExprWithType(c, n.sons[i]) - n.sons[i] = semExpr(c, buildStringify(c, arg)) - + n.sons[i] = semExprWithType(c, buildStringify(c, arg)) + let t = n.sons[i].typ + if t == nil or t.skipTypes(abstractInst).kind != tyString: + LocalError(n.info, errGenerated, + "implicitly invoked '$' does not return string") let t = n.sons[0].typ if tfNoSideEffect notin t.flags: incl(c.p.owner.flags, sfSideEffect) result = n |