diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-07-08 20:11:59 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-07-08 20:11:59 +0200 |
commit | 089c31765fd7d0fc2c4beb4869dd9a42c78b4ab8 (patch) | |
tree | dac3d792d304eaf414471d504ce5d78e7daf802c | |
parent | 1d186ee9c335a54ae9700110afe4ec9e888b7b9d (diff) | |
download | Nim-089c31765fd7d0fc2c4beb4869dd9a42c78b4ab8.tar.gz |
fixes #3055
-rw-r--r-- | compiler/seminst.nim | 2 | ||||
-rw-r--r-- | tests/generics/tforward_generic.nim | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim index e4ac56cd6..460db4f7c 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -205,7 +205,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable, # The solution would be to move this logic into semtypinst, but # at this point semtypinst have to become part of sem, because it # will need to use openScope, addDecl, etc. - addDecl(c, prc) + #addDecl(c, prc) pushInfoContext(info) var cl = initTypeVars(c, pt, info, nil) diff --git a/tests/generics/tforward_generic.nim b/tests/generics/tforward_generic.nim new file mode 100644 index 000000000..169279cb3 --- /dev/null +++ b/tests/generics/tforward_generic.nim @@ -0,0 +1,28 @@ +discard """ + output: '''b() +720 120.0''' +""" + +# bug #3055 +proc b(t: int | string) +proc a(t: int) = b(t) +proc b(t: int | string) = echo "b()" +a(1) + +# test recursive generics still work: +proc fac[T](x: T): T = + if x == 0: return 1 + else: return fac(x-1)*x + +echo fac(6), " ", fac(5.0) + +when false: + # This still doesn't work... + # test recursive generic with forwarding: + proc fac2[T](x: T): T + + echo fac2(6), " ", fac2(5.0) + + proc fac2[T](x: T): T = + if x == 0: return 1 + else: return fac2(x-1)*x |