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

Wrong overload resolution when using symbol instead of ident #11125

Open
bluenote10 opened this issue Apr 27, 2019 · 1 comment
Open

Wrong overload resolution when using symbol instead of ident #11125

bluenote10 opened this issue Apr 27, 2019 · 1 comment

Comments

@bluenote10
Copy link
Contributor

Another issue related to typed macro arguments (nim-lang/RFCs#44).

Example

import macros

type
  A = ref object of RootObj
  B = ref object of A

proc f(T: typedesc[A], x: A) =
  echo "only accepts A"

proc f(T: typedesc[B], x: B) =
  echo "only accepts B"

macro genCallToF(t: typed, x: untyped): untyped =
  result = newCall(ident "f", [t, newCall(t, x)])
  echo result.repr

let x1 = A()
let x2 = B()

# That's the ASTs produced by the macro
f(A, A(x1))
f(B, B(x2))

genCallToF(A, x1)
genCallToF(B, x2)

Current Output

The ASTs produced by the macro have different behavior than the manual ASTs:

only accepts A
only accepts B
only accepts A
only accepts A

Expected Output

The should behave the same:

only accepts A
only accepts B
only accepts A
only accepts B

Workaround

It looks like the problem is also caused by using symbols instead of idents. The problem disappears

  • when changing the macro arg to t: untyped or
  • when using the infamous "to untyped" trick. In this case it is needed for the type conversion call: newCall(ident t.strVal, x).

Additional Information

$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-04-13
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: f6ad071a46a2bec57db453343d8d8b75d3d16ac2
active boot switches: -d:release

Relevant project: https://github.com/bluenote10/oop_utils

@Araq Araq added the Severe label Apr 29, 2019
@krux02 krux02 added the Macros label Apr 30, 2019
@krux02 krux02 self-assigned this Apr 30, 2019
@krux02 krux02 removed the Severe label Aug 19, 2019
@krux02
Copy link
Contributor

krux02 commented Aug 19, 2019

I invested some time here to fix it. Without success. I remove High Priority here as there are just too many features thrown together at once.

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

4 participants