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

Two different macros cause variable name conflict #16680

Open
al6x opened this issue Jan 11, 2021 · 1 comment
Open

Two different macros cause variable name conflict #16680

al6x opened this issue Jan 11, 2021 · 1 comment

Comments

@al6x
Copy link

al6x commented Jan 11, 2021

The code below won't compile, because of redeclaration of the let a variable.

But if the second test template commented out it would work.

Example

playground

template test*(name: string, body) =
  block: body

template test*(name: string, group: string, body) =
  block: body

test "a1":
  let a = 1

test "a2":
  let a = 1

Current Output

Hint: used config file '/playground/nim/config/nim.cfg' [Conf]
Hint: used config file '/playground/nim/config/config.nims' [Conf]
....
/usercode/in.nim(8, 7) Hint: 'a' is declared but not used [XDeclaredButNotUsed]
/usercode/in.nim(11, 7) Error: redefinition of 'a'; previous declaration here: /usercode/in.nim(8, 7)
@metagn
Copy link
Collaborator

metagn commented Jan 11, 2021

The body argument to the first template gets typechecked as there is an overload on it where there is a typed argument in the same place. I think your best option for now is to remove the : string annotation on group. To fix this Nim needs to alter its overload semantics in a case like this where it's obvious the arities don't match, but that might be unpredictable.

Late edit: This means this is another case of #14827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants