parent
55373e65b4
commit
5536f74992
3 changed files with 27 additions and 8 deletions
|
|
@ -1389,7 +1389,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
rawAddSon(s.typ, newTypeS(tyNone, c))
|
rawAddSon(s.typ, newTypeS(tyNone, c))
|
||||||
s.ast = a
|
s.ast = a
|
||||||
inc c.inGenericContext
|
inc c.inGenericContext
|
||||||
var body = semTypeNode(c, a[2], nil)
|
var body = semTypeNode(c, a[2], s.typ)
|
||||||
dec c.inGenericContext
|
dec c.inGenericContext
|
||||||
if body != nil:
|
if body != nil:
|
||||||
body.sym = s
|
body.sym = s
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ const
|
||||||
errInOutFlagNotExtern = "the '$1' modifier can be used only with imported types"
|
errInOutFlagNotExtern = "the '$1' modifier can be used only with imported types"
|
||||||
|
|
||||||
proc newOrPrevType(kind: TTypeKind, prev: PType, c: PContext): PType =
|
proc newOrPrevType(kind: TTypeKind, prev: PType, c: PContext): PType =
|
||||||
if prev == nil:
|
if prev == nil or prev.kind == tyGenericBody:
|
||||||
result = newTypeS(kind, c)
|
result = newTypeS(kind, c)
|
||||||
else:
|
else:
|
||||||
result = prev
|
result = prev
|
||||||
|
|
@ -977,7 +977,7 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
|
||||||
let n = if n[0].kind == nkBracket: n[0] else: n
|
let n = if n[0].kind == nkBracket: n[0] else: n
|
||||||
checkMinSonsLen(n, 1, c.config)
|
checkMinSonsLen(n, 1, c.config)
|
||||||
let body = n.lastSon
|
let body = n.lastSon
|
||||||
var t = if prev != nil and body.kind == nkObjectTy:
|
var t = if prev != nil and prev.kind != tyGenericBody and body.kind == nkObjectTy:
|
||||||
semObjectNode(c, body, nil, prev.flags)
|
semObjectNode(c, body, nil, prev.flags)
|
||||||
else:
|
else:
|
||||||
semTypeNode(c, body, nil)
|
semTypeNode(c, body, nil)
|
||||||
|
|
@ -1575,21 +1575,23 @@ proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType =
|
||||||
result = newTypeS(tyAlias, c)
|
result = newTypeS(tyAlias, c)
|
||||||
result.rawAddSon typeExpr
|
result.rawAddSon typeExpr
|
||||||
result.sym = prev.sym
|
result.sym = prev.sym
|
||||||
assignType(prev, result)
|
if prev.kind != tyGenericBody:
|
||||||
|
assignType(prev, result)
|
||||||
|
|
||||||
proc fixupTypeOf(c: PContext, prev: PType, typExpr: PNode) =
|
proc fixupTypeOf(c: PContext, prev: PType, typExpr: PNode) =
|
||||||
if prev != nil:
|
if prev != nil:
|
||||||
let result = newTypeS(tyAlias, c)
|
let result = newTypeS(tyAlias, c)
|
||||||
result.rawAddSon typExpr.typ
|
result.rawAddSon typExpr.typ
|
||||||
result.sym = prev.sym
|
result.sym = prev.sym
|
||||||
assignType(prev, result)
|
if prev.kind != tyGenericBody:
|
||||||
|
assignType(prev, result)
|
||||||
|
|
||||||
proc semTypeExpr(c: PContext, n: PNode; prev: PType): PType =
|
proc semTypeExpr(c: PContext, n: PNode; prev: PType): PType =
|
||||||
var n = semExprWithType(c, n, {efDetermineType})
|
var n = semExprWithType(c, n, {efDetermineType})
|
||||||
if n.typ.kind == tyTypeDesc:
|
if n.typ.kind == tyTypeDesc:
|
||||||
result = n.typ.base
|
result = n.typ.base
|
||||||
# fix types constructed by macros/template:
|
# fix types constructed by macros/template:
|
||||||
if prev != nil and prev.sym != nil:
|
if prev != nil and prev.kind != tyGenericBody and prev.sym != nil:
|
||||||
if result.sym.isNil:
|
if result.sym.isNil:
|
||||||
# Behold! you're witnessing enormous power yielded
|
# Behold! you're witnessing enormous power yielded
|
||||||
# by macros. Only macros can summon unnamed types
|
# by macros. Only macros can summon unnamed types
|
||||||
|
|
@ -1610,7 +1612,7 @@ proc semTypeExpr(c: PContext, n: PNode; prev: PType): PType =
|
||||||
result = errorType(c)
|
result = errorType(c)
|
||||||
|
|
||||||
proc freshType(c: PContext; res, prev: PType): PType {.inline.} =
|
proc freshType(c: PContext; res, prev: PType): PType {.inline.} =
|
||||||
if prev.isNil:
|
if prev.isNil or prev.kind == tyGenericBody:
|
||||||
result = copyType(res, nextTypeId c.idgen, res.owner)
|
result = copyType(res, nextTypeId c.idgen, res.owner)
|
||||||
copyTypeProps(c.graph, c.idgen.module, result, res)
|
copyTypeProps(c.graph, c.idgen.module, result, res)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1988,6 +1990,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
let alias = maybeAliasType(c, s.typ, prev)
|
let alias = maybeAliasType(c, s.typ, prev)
|
||||||
if alias != nil:
|
if alias != nil:
|
||||||
result = alias
|
result = alias
|
||||||
|
elif prev.kind == tyGenericBody:
|
||||||
|
result = s.typ
|
||||||
else:
|
else:
|
||||||
assignType(prev, s.typ)
|
assignType(prev, s.typ)
|
||||||
# bugfix: keep the fresh id for aliases to integral types:
|
# bugfix: keep the fresh id for aliases to integral types:
|
||||||
|
|
@ -2007,7 +2011,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
let alias = maybeAliasType(c, t, prev)
|
let alias = maybeAliasType(c, t, prev)
|
||||||
if alias != nil:
|
if alias != nil:
|
||||||
result = alias
|
result = alias
|
||||||
elif prev == nil:
|
elif prev == nil or prev.kind == tyGenericBody:
|
||||||
result = t
|
result = t
|
||||||
else:
|
else:
|
||||||
assignType(prev, t)
|
assignType(prev, t)
|
||||||
|
|
|
||||||
15
tests/generics/t20996.nim
Normal file
15
tests/generics/t20996.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
discard """
|
||||||
|
action: compile
|
||||||
|
"""
|
||||||
|
|
||||||
|
import std/macros
|
||||||
|
|
||||||
|
macro matchMe(x: typed): untyped =
|
||||||
|
discard x.getTypeImpl
|
||||||
|
|
||||||
|
type
|
||||||
|
ElementRT = object
|
||||||
|
Element[Z] = ElementRT # this version is needed, even though we don't use it
|
||||||
|
|
||||||
|
let ar = ElementRT()
|
||||||
|
matchMe(ar)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue