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

Cannot hand multiple procs to macro using varargs[typed] #13913

Open
Vindaar opened this issue Apr 7, 2020 · 0 comments
Open

Cannot hand multiple procs to macro using varargs[typed] #13913

Vindaar opened this issue Apr 7, 2020 · 0 comments

Comments

@Vindaar
Copy link
Contributor

Vindaar commented Apr 7, 2020

I was writing some code where I wanted to get all possible overloads for different procedures in an untyped macro. The experimental dynamicBindSym actually worked for that, but @Araq advised against using it.

So I tried to hack my way around it by having a helper macro, which receives the results of bindSym calls as arguments. After being confused by "undeclared identifier errors" on another actually untyped argument (which turned out to be this really annoying bug: #12019), I figured out the problem is rather simple.

Example

import macros, math

macro foo(fns: varargs[typed]): untyped =
  for t in fns:
    echo t.treeRepr

foo(sqrt, pow, ln)

Current Output

/tmp/bug.nim(7, 4) Error: type mismatch: got <proc (x: float64): float64{.noSideEffect.} | proc (x: float32): float32{.noSideEffect.}, proc (x: float32, y: float32): float32{.noSideEffect.} | proc (x: float64, y: float64): float64{.noSideEffect.}, proc (x: float32): float32{.noSideEffect.} | proc (x: float64): float64{.noSideEffect.}>
but expected one of: 
macro foo(fns: varargs[typed]): untyped
  first type mismatch at position: 1
  required type for fns: varargs[typed]
  but expression 'sqrt' is of type: None

expression: foo(sqrt, pow, ln)

Expected Output

Each t in the for loop should be an nnkClosedSymChoice as in this example with a single proc and no varargs:

import macros, math

macro bar(fn: typed): untyped =
  echo fn.treeRepr

bar(sqrt)

Possible Solution

I'm not even sure if this is allowed and not actually a bug. But I don't know why it wouldn't. Every argument is just a NimNode, no?

Additional Information

I was on:

Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2020-04-02
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 46c827be6a959be3d3bb840d1582bac8fc55bda6
active boot switches: -d:release -d:danger

and just updated to current devel and the problem persists:

Nim Compiler Version 1.3.1 [Linux: amd64]
Compiled at 2020-04-07
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: ab5e26c53cf34a1839dd92d247b5e0a5cde432a0
active boot switches: -d:release -d:danger
@ghost ghost added Macros varargs labels Aug 4, 2020
ynfle added a commit to ynfle/Nim-1 that referenced this issue Jan 31, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Closes nim-lang#19446 & nim-lang#13913
ynfle added a commit to ynfle/Nim-1 that referenced this issue Jan 31, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Fixes nim-lang#19446
Fixes nim-lang#13913
ynfle added a commit to ynfle/Nim-1 that referenced this issue Jan 31, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Fixes nim-lang#19446 &
nim-lang#13913
ynfle added a commit to ynfle/Nim-1 that referenced this issue Jan 31, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Fixes nim-lang#19446 &
nim-lang#13913
ynfle added a commit to ynfle/Nim-1 that referenced this issue Jan 31, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Fixes nim-lang#19446 &
nim-lang#13913
ynfle added a commit to ynfle/Nim-1 that referenced this issue Feb 3, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Fixes nim-lang#19446 &
nim-lang#13913
ynfle added a commit to ynfle/Nim-1 that referenced this issue Apr 14, 2022
There was a bug that params wouldn't be matched if the param was
overloaded and the candidate type was varargs. This checks the base type
of the `varargs` and then will to an overloaded symbol if in a macros or
template.

Fixes nim-lang#19446 &
nim-lang#13913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant