-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
getTypeInst for generics does not gives the full instantiation info in certain cases #7737
Comments
The example is a bit verbose, I could boil it a bit down if that helps to fix the bug. It seems like varargs is causing the problem, because without varargs, it just works. import macros
type
CustomSeq*[T] = object
data*: seq[T]
# when using just one argument, `foo` and `bar` should be exactly
# identical.
macro foo(arg: typed): untyped =
echo arg.getTypeInst.treeRepr
macro bar(args: varargs[typed]): untyped =
for arg in args:
echo arg.getTypeInst.treeRepr
var
a: seq[int]
b: Custoimport macros
type
CustomSeq*[T] = object
data*: seq[T]
# when using just one argument, `foo` and `bar` should be exactly
# identical.
macro foo(arg: typed): untyped =
echo arg.getTypeInst.treeRepr
macro bar(args: varargs[typed]): untyped =
for arg in args:
echo arg.getTypeInst.treeRepr
var
a: seq[int]
b: CustomSeq[int]
# these two should print the exact same
foo(a) # prints seq[int], OK
bar(a) # prints seq[int], OK
foo(b) # prints CustomSeq[int], OK
# The following prints `CustomSeq` instead of `CustomSeq[int]`.
bar(b) # prints CustomSeq , Wrong
mSeq[int]
# these two should print the exact same
foo(a) # prints seq[int], OK
bar(a) # prints seq[int], OK
foo(b) # prints CustomSeq[int], OK
# The following prints `CustomSeq` instead of `CustomSeq[int]`.
bar(b) # prints CustomSeq , Wrong @mratsim as a workaround of the broken varargs you could write lots of overloads until varargs[typed] will work again. macro typed_helper(arg1: typed): untyped = #[ ... ]#
macro typed_helper(arg1,arg2: typed): untyped = #[ ... ]#
macro typed_helper(arg1,arg2,arg3: typed): untyped = #[ ... ]#
macro typed_helper(arg1,arg2,arg3,arg4: typed): untyped = #[ ... ]#
... |
The problem (?) is here, I don't know much about the sigmatch internals to suggest a solution though. |
Seems to work in devel |
closes nim-lang#1969, closes nim-lang#7737, closes nim-lang#11838, closes nim-lang#12283, closes nim-lang#14053, closes nim-lang#16118, closes nim-lang#19670, closes nim-lang#22645
Another case of difficulties working with types #7719/nim-lang/RFCs#44 and subtypes #6454 in macros.
In the following case I am trying to extract a subtype of multiple containers. It works fine for the built-in seq but not for a generic type. The subtype is not available through getTypeInst.
The text was updated successfully, but these errors were encountered: