From 347a04606bddbb49f05e86188d96889617ce5136 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 13 Dec 2019 19:20:29 +0100 Subject: [PATCH] fixes #12885 [backport] (#12895) --- compiler/semtempl.nim | 4 ++++ tests/tools/second.nim | 3 +++ tests/tools/tunused_imports.nim | 13 +++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/tools/second.nim diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index fbeae2b0725ea..dedea2e99597a 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -242,6 +242,10 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) = proc semTemplSymbol(c: PContext, n: PNode, s: PSym; isField: bool): PNode = incl(s.flags, sfUsed) + # bug #12885; ideally sem'checking is performed again afterwards marking + # the symbol as used properly, but the nfSem mechanism currently prevents + # that from happening, so we mark the module as used here already: + markOwnerModuleAsUsed(c, s) # we do not call onUse here, as the identifier is not really # resolved here. We will fixup the used identifiers later. case s.kind diff --git a/tests/tools/second.nim b/tests/tools/second.nim new file mode 100644 index 0000000000000..0dbe72adbba2d --- /dev/null +++ b/tests/tools/second.nim @@ -0,0 +1,3 @@ +import tables + +let dataEx* = {1: 2, 3: 4}.toTable diff --git a/tests/tools/tunused_imports.nim b/tests/tools/tunused_imports.nim index 1c5732c83e4ce..bce9066346d91 100644 --- a/tests/tools/tunused_imports.nim +++ b/tests/tools/tunused_imports.nim @@ -2,14 +2,23 @@ discard """ cmd: '''nim c --hint[Processing]:off $file''' nimout: ''' tunused_imports.nim(11, 10) Warning: BEGIN [User] -tunused_imports.nim(27, 10) Warning: END [User] -tunused_imports.nim(25, 8) Warning: imported and not used: 'strutils' [UnusedImport] +tunused_imports.nim(36, 10) Warning: END [User] +tunused_imports.nim(34, 8) Warning: imported and not used: 'strutils' [UnusedImport] ''' action: "compile" """ {.warning: "BEGIN".} +# bug #12885 + +import tables, second + +template test(key: int): untyped = + `[]`(dataEx, key) + +echo test(1) + import net, dontmentionme echo AF_UNIX