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 use a typedesc variable in a template #9611

bluenote10 opened this issue Nov 3, 2018 · 1 comment


None yet
3 participants
Copy link

commented Nov 3, 2018

Passing a typedesc to a template seems to fail when the parameter is a typedesc variable:


proc aProc(A: typedesc) =
  var a: A

template aTemplate(A: typedesc) = 
  var a: A

var T: typedesc[int]
aProc(int)       # works with concrete type
aTemplate(int)   # works with concrete type
aProc(T)         # works with typedesc variable
aTemplate(T)     # fails with typedesc variable

Current Output

test.nim(11, 11) Error: type expected

Interestingly passing the typedesc variable to the template works, if the template does not use the type explicitly in variable/type/function definitions and only calls procs that take typedescs. For instance the code compiles when changing the typedesc to

template aTemplate(A: typedesc) = 

The common work-around of using a local type alias like type AA = A doesn't seem to help here.


This comment has been minimized.

Copy link

commented Nov 3, 2018

var T: typedesc[int] is not valid Nim and should be rejected.

@dom96 dom96 added the Error messages label Nov 3, 2018

@Araq Araq closed this in ae27f8a Nov 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.