fixes #3055
This commit is contained in:
parent
1d186ee9c3
commit
089c31765f
2 changed files with 29 additions and 1 deletions
|
|
@ -205,7 +205,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
# The solution would be to move this logic into semtypinst, but
|
# The solution would be to move this logic into semtypinst, but
|
||||||
# at this point semtypinst have to become part of sem, because it
|
# at this point semtypinst have to become part of sem, because it
|
||||||
# will need to use openScope, addDecl, etc.
|
# will need to use openScope, addDecl, etc.
|
||||||
addDecl(c, prc)
|
#addDecl(c, prc)
|
||||||
|
|
||||||
pushInfoContext(info)
|
pushInfoContext(info)
|
||||||
var cl = initTypeVars(c, pt, info, nil)
|
var cl = initTypeVars(c, pt, info, nil)
|
||||||
|
|
|
||||||
28
tests/generics/tforward_generic.nim
Normal file
28
tests/generics/tforward_generic.nim
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue