From d72921ecf6b3c62fdc0be2c179752ee08b4169b8 Mon Sep 17 00:00:00 2001 From: alaviss Date: Thu, 24 Jan 2019 18:22:19 +0700 Subject: [PATCH] compiler/sem: correct macros lineinfo (#10438) The compiler believes these are where a macro call starts (marked with `^`): m "string" ^ ^ This commit addresses that. --- compiler/sem.nim | 9 +++++---- nimsuggest/tests/tmacro_highlight.nim | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 nimsuggest/tests/tmacro_highlight.nim diff --git a/compiler/sem.nim b/compiler/sem.nim index 3763c9b84c..0a3b60ab35 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -450,17 +450,18 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym, flags: TExprFlags = {}): PNode = pushInfoContext(c.config, nOrig.info, sym.detailedInfo) - markUsed(c.config, n.info, sym, c.graph.usageSym) - onUse(n.info, sym) + let info = getCallLineInfo(n) + markUsed(c.config, info, sym, c.graph.usageSym) + onUse(info, sym) if sym == c.p.owner: - globalError(c.config, n.info, "recursive dependency: '$1'" % sym.name.s) + globalError(c.config, info, "recursive dependency: '$1'" % sym.name.s) let genericParams = if sfImmediate in sym.flags: 0 else: sym.ast[genericParamsPos].len let suppliedParams = max(n.safeLen - 1, 0) if suppliedParams < genericParams: - globalError(c.config, n.info, errMissingGenericParamsForTemplate % n.renderTree) + globalError(c.config, info, errMissingGenericParamsForTemplate % n.renderTree) #if c.evalContext == nil: # c.evalContext = c.createEvalContext(emStatic) diff --git a/nimsuggest/tests/tmacro_highlight.nim b/nimsuggest/tests/tmacro_highlight.nim new file mode 100644 index 0000000000..6f5b5e8a70 --- /dev/null +++ b/nimsuggest/tests/tmacro_highlight.nim @@ -0,0 +1,13 @@ +macro a(b: string): untyped = discard + +a "string"#[!]# + +discard """ +$nimsuggest --tester $file +>highlight $1 +highlight;;skMacro;;1;;6;;1 +highlight;;skType;;1;;11;;6 +highlight;;skType;;1;;20;;7 +highlight;;skMacro;;3;;0;;1 +highlight;;skMacro;;3;;0;;1 +"""