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

[Macro] Type mismatch when parameter name is the same as a field #13253

Closed
nitely opened this issue Jan 24, 2020 · 1 comment
Closed

[Macro] Type mismatch when parameter name is the same as a field #13253

nitely opened this issue Jan 24, 2020 · 1 comment

Comments

@nitely
Copy link
Contributor

nitely commented Jan 24, 2020

Naming a static object parameter the same as one of their fields produces a type mismatch when it's passed to a macro. Removing the macro make it work as expected. I found this while trying to make a snippet for #13252

Example

import macros

type
  FooBar = object
    a: seq[int]

macro genFoobar(a: static FooBar): untyped =
  result = newStmtList()
  for b in a.a:
    result.add(newCall(bindSym"echo", newLit b))

proc foobar(a: static FooBar) =
  genFoobar(a)  # removing this make it work
  for b in a.a:
    echo "foo" & $b

proc main() =
  const a: seq[int] = @[1, 2,3]
  # Error: type mismatch: got <array[0..2, int]> but expected 'seq[int]'
  const fb = Foobar(a: a)
  foobar(fb)
main()

Current Output

Error: type mismatch: got <array[0..2, int]> but expected 'seq[int]'

Expected Output

1
2
3
foo1
foo2
foo3

Additional Information

  • Tried in Nim devel and 1.0.4
$ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2020-01-24
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release
@ringabout
Copy link
Member

It works in devel.

D:\QQPCmgr\Desktop\fight\Nim>nim -v
Nim Compiler Version 1.3.5 [Windows: amd64]
Compiled at 2020-07-01
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 1440e70c62e7dc2e2a2062c1291f65c12055818a
active boot switches: -d:release

Output(>nim c -r test.nim)

1
2
3
foo1
foo2
foo3

Clyybber added a commit to Clyybber/Nim that referenced this issue Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants