fixes #117
This commit is contained in:
parent
3aa36a8568
commit
af441e607f
4 changed files with 35 additions and 7 deletions
|
|
@ -72,6 +72,10 @@ proc commonType*(x, y: PType): PType =
|
||||||
elif b.kind in {tyExpr, tyNil}: result = x
|
elif b.kind in {tyExpr, tyNil}: result = x
|
||||||
elif a.kind == tyStmt: result = a
|
elif a.kind == tyStmt: result = a
|
||||||
elif b.kind == tyStmt: result = b
|
elif b.kind == tyStmt: result = b
|
||||||
|
elif a.kind == tyTypeDesc:
|
||||||
|
# turn any concrete typedesc into the abstract typedesc type
|
||||||
|
if a.sons == nil: result = a
|
||||||
|
else: result = newType(tyTypeDesc, a.owner)
|
||||||
elif b.kind in {tyArray, tyArrayConstr, tySet, tySequence} and
|
elif b.kind in {tyArray, tyArrayConstr, tySet, tySequence} and
|
||||||
a.kind == b.kind:
|
a.kind == b.kind:
|
||||||
# check for seq[empty] vs. seq[int]
|
# check for seq[empty] vs. seq[int]
|
||||||
|
|
|
||||||
|
|
@ -402,10 +402,10 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
indexType = idx.typ
|
indexType = idx.typ
|
||||||
x = x.sons[1]
|
x = x.sons[1]
|
||||||
|
|
||||||
addSon(result, semExprWithType(c, x))
|
let yy = semExprWithType(c, x)
|
||||||
var typ = skipTypes(result.sons[0].typ, {tyGenericInst, tyVar, tyOrdinal})
|
var typ = yy.typ
|
||||||
# turn any concrete typedesc into the absract typedesc type
|
addSon(result, yy)
|
||||||
if typ.kind == tyTypeDesc: typ.sons = nil
|
#var typ = skipTypes(result.sons[0].typ, {tyGenericInst, tyVar, tyOrdinal})
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
x = n.sons[i]
|
x = n.sons[i]
|
||||||
if x.kind == nkExprColonExpr and sonsLen(x) == 2:
|
if x.kind == nkExprColonExpr and sonsLen(x) == 2:
|
||||||
|
|
@ -415,10 +415,15 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
localError(x.info, errInvalidOrderInArrayConstructor)
|
localError(x.info, errInvalidOrderInArrayConstructor)
|
||||||
x = x.sons[1]
|
x = x.sons[1]
|
||||||
|
|
||||||
n.sons[i] = semExprWithType(c, x, flags*{efAllowDestructor})
|
let xx = semExprWithType(c, x, flags*{efAllowDestructor})
|
||||||
addSon(result, fitNode(c, typ, n.sons[i]))
|
result.add xx
|
||||||
|
typ = commonType(typ, xx.typ)
|
||||||
|
#n.sons[i] = semExprWithType(c, x, flags*{efAllowDestructor})
|
||||||
|
#addSon(result, fitNode(c, typ, n.sons[i]))
|
||||||
inc(lastIndex)
|
inc(lastIndex)
|
||||||
addSonSkipIntLit(result.typ, typ)
|
addSonSkipIntLit(result.typ, typ)
|
||||||
|
for i in 0 .. <result.len:
|
||||||
|
result.sons[i] = fitNode(c, typ, result.sons[i])
|
||||||
result.typ.sons[0] = makeRangeType(c, 0, sonsLen(result) - 1, n.info)
|
result.typ.sons[0] = makeRangeType(c, 0, sonsLen(result) - 1, n.info)
|
||||||
|
|
||||||
proc fixAbstractType(c: PContext, n: PNode) =
|
proc fixAbstractType(c: PContext, n: PNode) =
|
||||||
|
|
|
||||||
20
tests/compile/tcommontype.nim
Normal file
20
tests/compile/tcommontype.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
type
|
||||||
|
TAnimal=object {.inheritable.}
|
||||||
|
PAnimal=ref TAnimal
|
||||||
|
|
||||||
|
TDog=object of TAnimal
|
||||||
|
PDog=ref TDog
|
||||||
|
|
||||||
|
TCat=object of TAnimal
|
||||||
|
PCat=ref TCat
|
||||||
|
|
||||||
|
TAnimalArray=array[0..2,PAnimal]
|
||||||
|
|
||||||
|
proc newDog():PDog = new(result)
|
||||||
|
proc newCat():PCat = new(result)
|
||||||
|
proc test(a:openarray[PAnimal])=
|
||||||
|
echo("dummy")
|
||||||
|
|
||||||
|
#test(newDog(),newCat()) #does not work
|
||||||
|
var myarray:TAnimalArray=[newDog(),newCat(),newDog()] #does not work
|
||||||
|
#var myarray2:TAnimalArray=[newDog(),newDog(),newDog()] #does not work either
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -7,7 +7,6 @@ version 0.9.2
|
||||||
- acyclic vs prunable; introduce GC hints
|
- acyclic vs prunable; introduce GC hints
|
||||||
- CGEN: ``restrict`` pragma + backend support; computed goto support
|
- CGEN: ``restrict`` pragma + backend support; computed goto support
|
||||||
- document NimMain and check whether it works for threading
|
- document NimMain and check whether it works for threading
|
||||||
- make use of commonType relation in expressions
|
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
====
|
====
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue