fix getTypeInst for tyGenericInst (#6868)
This commit is contained in:
parent
c039bbf6e1
commit
35d7a99b6a
2 changed files with 32 additions and 9 deletions
|
|
@ -121,22 +121,25 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
||||||
for i in 0 ..< t.len:
|
for i in 0 ..< t.len:
|
||||||
result.add mapTypeToAst(t.sons[i], info)
|
result.add mapTypeToAst(t.sons[i], info)
|
||||||
of tyGenericInst, tyAlias:
|
of tyGenericInst:
|
||||||
if inst:
|
if inst:
|
||||||
if allowRecursion:
|
if allowRecursion:
|
||||||
result = mapTypeToAstR(t.lastSon, info)
|
result = mapTypeToAstR(t.lastSon, info)
|
||||||
else:
|
else:
|
||||||
result = newNodeX(nkBracketExpr)
|
result = newNodeX(nkBracketExpr)
|
||||||
result.add mapTypeToAst(t.lastSon, info)
|
#result.add mapTypeToAst(t.lastSon, info)
|
||||||
|
result.add mapTypeToAst(t[0], info)
|
||||||
for i in 1 ..< t.len-1:
|
for i in 1 ..< t.len-1:
|
||||||
result.add mapTypeToAst(t.sons[i], info)
|
result.add mapTypeToAst(t.sons[i], info)
|
||||||
else:
|
else:
|
||||||
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
||||||
of tyGenericBody:
|
of tyGenericBody:
|
||||||
if inst:
|
if inst:
|
||||||
result = mapTypeToAstX(t.lastSon, info, inst, true)
|
result = mapTypeToAstR(t.lastSon, info)
|
||||||
else:
|
else:
|
||||||
result = mapTypeToAst(t.lastSon, info)
|
result = mapTypeToAst(t.lastSon, info)
|
||||||
|
of tyAlias:
|
||||||
|
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
||||||
of tyOrdinal:
|
of tyOrdinal:
|
||||||
result = mapTypeToAst(t.lastSon, info)
|
result = mapTypeToAst(t.lastSon, info)
|
||||||
of tyDistinct:
|
of tyDistinct:
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,9 @@ macro testX(x,inst0: typed; recurse: static[bool]; implX: typed): typed =
|
||||||
let inst = x.getTypeInst
|
let inst = x.getTypeInst
|
||||||
let instr = inst.symToIdent.treeRepr
|
let instr = inst.symToIdent.treeRepr
|
||||||
let inst0r = inst0.symToIdent.treeRepr
|
let inst0r = inst0.symToIdent.treeRepr
|
||||||
#echo instr
|
if instr != inst0r:
|
||||||
#echo inst0r
|
echo "instr:\n", instr
|
||||||
|
echo "inst0r:\n", inst0r
|
||||||
doAssert(instr == inst0r)
|
doAssert(instr == inst0r)
|
||||||
|
|
||||||
# check that getTypeImpl(x) is correct
|
# check that getTypeImpl(x) is correct
|
||||||
|
|
@ -41,8 +42,9 @@ macro testX(x,inst0: typed; recurse: static[bool]; implX: typed): typed =
|
||||||
else: implX[0][2]
|
else: implX[0][2]
|
||||||
let implr = impl.symToIdent.treerepr
|
let implr = impl.symToIdent.treerepr
|
||||||
let impl0r = impl0.symToIdent.treerepr
|
let impl0r = impl0.symToIdent.treerepr
|
||||||
#echo implr
|
if implr != impl0r:
|
||||||
#echo impl0r
|
echo "implr:\n", implr
|
||||||
|
echo "impl0r:\n", impl0r
|
||||||
doAssert(implr == impl0r)
|
doAssert(implr == impl0r)
|
||||||
|
|
||||||
result = newStmtList()
|
result = newStmtList()
|
||||||
|
|
@ -111,6 +113,14 @@ type
|
||||||
Generic[T] = seq[int]
|
Generic[T] = seq[int]
|
||||||
Concrete = Generic[int]
|
Concrete = Generic[int]
|
||||||
|
|
||||||
|
Alias1 = float
|
||||||
|
Alias2 = Concrete
|
||||||
|
|
||||||
|
Vec[N: static[int],T] = object
|
||||||
|
arr: array[N,T]
|
||||||
|
Vec4[T] = Vec[4,T]
|
||||||
|
|
||||||
|
|
||||||
test(bool)
|
test(bool)
|
||||||
test(char)
|
test(char)
|
||||||
test(int)
|
test(int)
|
||||||
|
|
@ -149,6 +159,16 @@ test(Generic[int]):
|
||||||
type _ = seq[int]
|
type _ = seq[int]
|
||||||
test(Generic[float]):
|
test(Generic[float]):
|
||||||
type _ = seq[int]
|
type _ = seq[int]
|
||||||
|
test(Alias1):
|
||||||
|
type _ = float
|
||||||
|
test(Alias2):
|
||||||
|
type _ = Generic[int]
|
||||||
|
test(Vec[4,float32]):
|
||||||
|
type _ = object
|
||||||
|
arr: array[0..3,float32]
|
||||||
|
test(Vec4[float32]):
|
||||||
|
type _ = object
|
||||||
|
arr: array[0..3,float32]
|
||||||
|
|
||||||
# bug #4862
|
# bug #4862
|
||||||
static:
|
static:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue