implement the 'bind' statement for generics, it was an oversight that this was never implemented (#14584)

This commit is contained in:
Andreas Rumpf 2020-06-07 09:55:56 +02:00 • committed by GitHub
commit 66c50c2ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View 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))