fix #5658
This commit is contained in:
parent
e11b3520ff
commit
0b7321651e
3 changed files with 36 additions and 4 deletions
|
|
@ -851,9 +851,12 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
|
||||||
# type aliases are hard:
|
# type aliases are hard:
|
||||||
var t = semTypeNode(c, x, nil)
|
var t = semTypeNode(c, x, nil)
|
||||||
assert t != nil
|
assert t != nil
|
||||||
if t.kind in {tyObject, tyEnum, tyDistinct}:
|
if s.typ != nil and s.typ.kind != tyAlias:
|
||||||
assert s.typ != nil
|
if t.kind in {tyProc, tyGenericInst} and not t.isMetaType:
|
||||||
if s.typ.kind != tyAlias:
|
assignType(s.typ, t)
|
||||||
|
s.typ.id = t.id
|
||||||
|
elif t.kind in {tyObject, tyEnum, tyDistinct}:
|
||||||
|
assert s.typ != nil
|
||||||
assignType(s.typ, t)
|
assignType(s.typ, t)
|
||||||
s.typ.id = t.id # same id
|
s.typ.id = t.id # same id
|
||||||
checkConstructedType(s.info, s.typ)
|
checkConstructedType(s.info, s.typ)
|
||||||
|
|
|
||||||
|
|
@ -893,7 +893,13 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
let lifted = liftingWalk(paramType.sons[i])
|
let lifted = liftingWalk(paramType.sons[i])
|
||||||
if lifted != nil: paramType.sons[i] = lifted
|
if lifted != nil: paramType.sons[i] = lifted
|
||||||
|
|
||||||
if paramType.base.lastSon.kind == tyUserTypeClass:
|
let body = paramType.base
|
||||||
|
if body.kind == tyForward:
|
||||||
|
# this may happen for proc type appearing in a type section
|
||||||
|
# before one of its param types
|
||||||
|
return
|
||||||
|
|
||||||
|
if body.lastSon.kind == tyUserTypeClass:
|
||||||
let expanded = instGenericContainer(c, info, paramType,
|
let expanded = instGenericContainer(c, info, paramType,
|
||||||
allowMetaTypes = true)
|
allowMetaTypes = true)
|
||||||
result = liftingWalk(expanded, true)
|
result = liftingWalk(expanded, true)
|
||||||
|
|
@ -1067,6 +1073,7 @@ proc semBlockType(c: PContext, n: PNode, prev: PType): PType =
|
||||||
|
|
||||||
proc semGenericParamInInvocation(c: PContext, n: PNode): PType =
|
proc semGenericParamInInvocation(c: PContext, n: PNode): PType =
|
||||||
result = semTypeNode(c, n, nil)
|
result = semTypeNode(c, n, nil)
|
||||||
|
n.typ = makeTypeDesc(c, result)
|
||||||
|
|
||||||
proc semObjectTypeForInheritedGenericInst(c: PContext, n: PNode, t: PType) =
|
proc semObjectTypeForInheritedGenericInst(c: PContext, n: PNode, t: PType) =
|
||||||
var
|
var
|
||||||
|
|
|
||||||
22
tests/types/thard_tyforward.nim
Executable file
22
tests/types/thard_tyforward.nim
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
type
|
||||||
|
Bar[T] = Foo[T, T]
|
||||||
|
Baz[T] = proc (x: Foo[T, T])
|
||||||
|
|
||||||
|
GenericAlias[T] = Foo[T]
|
||||||
|
GenericAlias2[T] = Foo[Baz[T]]
|
||||||
|
|
||||||
|
Concrete1 = Foo[int, float]
|
||||||
|
Concrete2 = proc(x: proc(a: Foo[int, float]))
|
||||||
|
|
||||||
|
Foo[T, U] = object
|
||||||
|
x: T
|
||||||
|
y: U
|
||||||
|
|
||||||
|
var
|
||||||
|
x1: Bar[float]
|
||||||
|
x2: Baz[int]
|
||||||
|
x3: Concrete1
|
||||||
|
x4: Concrete2
|
||||||
|
x5: GenericAlias[int]
|
||||||
|
x6: GenericAlias2[string]
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue