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

Using generics in template where instantiate a object with generics got a compile error #10167

Closed
lguzzon opened this issue Jan 2, 2019 · 3 comments

Comments

@lguzzon
Copy link
Contributor

lguzzon commented Jan 2, 2019

Using generics in template where instantiate a object with generics got a compile error

Example

type
  Maybe* [T] =  object {. final .}
    case hasValue*: bool
    of true: value*: T
    else: discard


proc Just* [T](aValue: T): Maybe[T] {. inline .} =
  result = Maybe[T](hasValue: true, value: aValue)

template template_Just* [T](aValue: T): Maybe[T] =
  Maybe[T](hasValue: true, value: aValue)

proc Nothing* [T]: Maybe[T] {. inline .} =
  result = Maybe[T](hasValue: false)

echo Just[int](1)
echo template_Just[int](1)

Current Output

Hint: used config file 'C:\Users\a72c\scoop\apps\nim\current\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: issueTemplateGenerics [Processing]
issueTemplateGenerics.nim(22, 24) template/generic instantiation from here
issueTemplateGenerics.nim(13, 8) Error: cannot instantiate Maybe
got: <int>
but expected: <T>

Code compiled with Nim (nim 0.19.2)

Expected Output

(hasValue: true, value: 1)
(hasValue: true, value: 1)

See here code compiled with Nim (nim 0.16.0)

Possible Solution

Additional Information

@bluenote10
Copy link
Contributor

Duplicate of #5926?

@lguzzon
Copy link
Contributor Author

lguzzon commented Jan 2, 2019

Yes!!!
Thanks

@krux02
Copy link
Contributor

krux02 commented Jan 2, 2019

Closing this because it is a duplicate.

@krux02 krux02 closed this as completed Jan 2, 2019
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