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

Problem with templates in type definitions #4228

Closed
vegansk opened this issue May 27, 2016 · 1 comment · Fixed by #24005
Closed

Problem with templates in type definitions #4228

vegansk opened this issue May 27, 2016 · 1 comment · Fixed by #24005

Comments

@vegansk
Copy link
Contributor

vegansk commented May 27, 2016

The code:

template seqType(t: typedesc): typedesc =
  when t is int:
    seq[int]
  else:
    seq[string]

proc mkSeq[T: int|string](v: T): seqType(T) =
  result = newSeq[T](1)
  result[0] = v

echo mkSeq("a")
# Fails here
echo mkSeq(1)

fails to compile with the message:

typetest.nim(13, 11) template/generic instantiation from here
typetest.nim(8, 21) Error: type mismatch: got (seq[int]) but expected 'seq[string]'
@vegansk
Copy link
Contributor Author

vegansk commented May 27, 2016

The problem is that t is tyTypeDesc(tyGenericParam T) here: https://github.com/nim-lang/Nim/blob/devel/compiler/vm.nim#L1083. That's why VM chooses else branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment