From 91935fd915ce643472c81e11a04d1531eacad6e9 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 18 Dec 2016 20:21:50 +0100 Subject: fixes #4308, fixes #4905 --- compiler/cgen.nim | 2 ++ compiler/evaltempl.nim | 21 ++++++++++++++++++++- compiler/sem.nim | 1 + tests/errmsgs/tdont_show_system.nim | 13 +++++++++++++ tests/errmsgs/tproper_stacktrace.nim | 11 +++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/tdont_show_system.nim create mode 100644 tests/errmsgs/tproper_stacktrace.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 81d13140d..085e08990 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -194,6 +194,8 @@ proc genLineDir(p: BProc, t: PNode) = var tt = t #while tt.kind in {nkStmtListExpr}+nkCallKinds: # tt = tt.lastSon + if tt.kind in nkCallKinds and tt.len > 1: + tt = tt.sons[1] let line = tt.info.safeLineNm if optEmbedOrigSrc in gGlobalOptions: diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim index 96ede44fd..59f04ca84 100644 --- a/compiler/evaltempl.nim +++ b/compiler/evaltempl.nim @@ -104,6 +104,25 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode = var evalTemplateCounter* = 0 # to prevent endless recursion in templates instantiation +proc wrapInComesFrom*(info: TLineInfo; res: PNode): PNode = + when true: + result = res + result.info = info + if result.kind in {nkStmtList, nkStmtListExpr}: + result.lastSon.info = info + when false: + # this hack is required to + var x = result + while x.kind == nkStmtListExpr: x = x.lastSon + if x.kind in nkCallKinds: + for i in 1.. 100: @@ -132,5 +151,5 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode = #if ctx.instLines: result.info = n.info for i in countup(0, safeLen(body) - 1): evalTemplateAux(body.sons[i], args, ctx, result) - + result = wrapInComesFrom(n.info, result) dec(evalTemplateCounter) diff --git a/compiler/sem.nim b/compiler/sem.nim index 02c779ef0..069b7ea76 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -369,6 +369,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym, result = evalMacroCall(c.module, c.cache, n, nOrig, sym) if efNoSemCheck notin flags: result = semAfterMacroCall(c, result, sym, flags) + result = wrapInComesFrom(nOrig.info, result) popInfoContext() proc forceBool(c: PContext, n: PNode): PNode = diff --git a/tests/errmsgs/tdont_show_system.nim b/tests/errmsgs/tdont_show_system.nim new file mode 100644 index 000000000..6963a8a3f --- /dev/null +++ b/tests/errmsgs/tdont_show_system.nim @@ -0,0 +1,13 @@ +discard """ + errormsg: "value of type 'bool' has to be discarded" + line: 13 + file: "tdont_show_system.nim" +""" + +# bug #4308 + +#proc getGameTile: int = +# 1 > 0 + +# bug #4905 subsumes the problem of #4308: +true notin {false} diff --git a/tests/errmsgs/tproper_stacktrace.nim b/tests/errmsgs/tproper_stacktrace.nim new file mode 100644 index 000000000..57e65fa6f --- /dev/null +++ b/tests/errmsgs/tproper_stacktrace.nim @@ -0,0 +1,11 @@ +discard """ + outputsub: '''tproper_stacktrace.nim(7) tproper_stacktrace''' + exitcode: 1 +""" + +template fuzzy(x) = + echo x[] != 9 + +var p: ptr int +fuzzy p + -- cgit 1.4.1-2-gfad0