Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1027; disallow templates to use ambiguous identifiers #20631

Merged
merged 6 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
result = newSymNode(s, n.info)
onUse(n.info, s)
else:
if s.kind in {skType, skVar, skLet, skConst}:
discard qualifiedLookUp(c.c, n, {checkAmbiguity, checkModule})
result = semTemplSymbol(c.c, n, s, c.noGenSym > 0)
of nkBind:
result = semTemplBody(c, n[0])
Expand Down
1 change: 1 addition & 0 deletions tests/template/m1027a.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const version_str* = "mod a"
1 change: 1 addition & 0 deletions tests/template/m1027b.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const version_str* = "mod b"
22 changes: 22 additions & 0 deletions tests/template/t1027.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
discard """
cmd: "nim check --hints:off $file"
errormsg: ""
nimout: '''
t1027.nim(20, 19) Error: ambiguous identifier: 'version_str' -- use one of the following:
m1027a.version_str: string
m1027b.version_str: string
'''
"""






import m1027a, m1027b

# bug #1027
template wrap_me(stuff): untyped =
echo "Using " & version_str

wrap_me("hey")