implement the 'bind' statement for generics, it was an oversight that this was never implemented (#14584)
This commit is contained in:
parent
51b71e35f2
commit
66c50c2ffc
2 changed files with 28 additions and 4 deletions
17
tests/lookups/tbind_for_generics.nim
Normal file
17
tests/lookups/tbind_for_generics.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
errormsg: "type mismatch: got <Foo, Foo>"
|
||||
line: 8
|
||||
"""
|
||||
proc g[T](x: T) =
|
||||
bind `+`
|
||||
# because we bind `+` here, we must not find the `+` for 'Foo' below:
|
||||
echo x + x
|
||||
|
||||
type
|
||||
Foo = object
|
||||
a: int
|
||||
|
||||
proc `+`(a, b: Foo): Foo = Foo(a: a.a+b.a)
|
||||
|
||||
g(3)
|
||||
g(Foo(a: 8))
|
||||
Loading…
Add table
Add a link
Reference in a new issue