* defer skiptypes * defer skiptypes for tyRef & tyPtr * remove unneeded skipTypes
This commit is contained in:
parent
a075a912cf
commit
25a41d5d90
3 changed files with 52 additions and 3 deletions
|
|
@ -158,7 +158,7 @@ proc commonType*(x, y: PType): PType =
|
||||||
a = a.lastSon.skipTypes({tyGenericInst})
|
a = a.lastSon.skipTypes({tyGenericInst})
|
||||||
b = b.lastSon.skipTypes({tyGenericInst})
|
b = b.lastSon.skipTypes({tyGenericInst})
|
||||||
if a.kind == tyObject and b.kind == tyObject:
|
if a.kind == tyObject and b.kind == tyObject:
|
||||||
result = commonSuperclass(a, b)
|
result = commonSuperclass(a, b, k)
|
||||||
# this will trigger an error later:
|
# this will trigger an error later:
|
||||||
if result.isNil or result == a: return x
|
if result.isNil or result == a: return x
|
||||||
if result == b: return y
|
if result == b: return y
|
||||||
|
|
|
||||||
|
|
@ -1043,7 +1043,7 @@ proc inheritanceDiff*(a, b: PType): int =
|
||||||
inc(result)
|
inc(result)
|
||||||
result = high(int)
|
result = high(int)
|
||||||
|
|
||||||
proc commonSuperclass*(a, b: PType): PType =
|
proc commonSuperclass*(a, b: PType, k: TTypeKind): PType =
|
||||||
# quick check: are they the same?
|
# quick check: are they the same?
|
||||||
if sameObjectTypes(a, b): return a
|
if sameObjectTypes(a, b): return a
|
||||||
|
|
||||||
|
|
@ -1059,8 +1059,12 @@ proc commonSuperclass*(a, b: PType): PType =
|
||||||
x = x.sons[0]
|
x = x.sons[0]
|
||||||
var y = b
|
var y = b
|
||||||
while y != nil:
|
while y != nil:
|
||||||
|
var t = y # bug #7818, save type before skip
|
||||||
y = skipTypes(y, skipPtrs)
|
y = skipTypes(y, skipPtrs)
|
||||||
if ancestors.contains(y.id): return y
|
if ancestors.contains(y.id):
|
||||||
|
# bug #7818, defer the previous skipTypes
|
||||||
|
if k in {tyRef, tyPtr}: t = y
|
||||||
|
return t
|
||||||
y = y.sons[0]
|
y = y.sons[0]
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
45
tests/array/t7818.nim
Normal file
45
tests/array/t7818.nim
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
discard """
|
||||||
|
msg: '''BracketExpr
|
||||||
|
Sym "array"
|
||||||
|
Infix
|
||||||
|
Ident ".."
|
||||||
|
IntLit 0
|
||||||
|
IntLit 2
|
||||||
|
BracketExpr
|
||||||
|
Sym "Vehicle"
|
||||||
|
Sym "int"
|
||||||
|
---------
|
||||||
|
BracketExpr
|
||||||
|
Sym "array"
|
||||||
|
Infix
|
||||||
|
Ident ".."
|
||||||
|
IntLit 0
|
||||||
|
IntLit 2
|
||||||
|
BracketExpr
|
||||||
|
Sym "Vehicle"
|
||||||
|
Sym "int"
|
||||||
|
---------'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #7818
|
||||||
|
# this is not a macro bug, but array construction bug
|
||||||
|
# I use macro to avoid object slicing
|
||||||
|
# see #7712 and #7637
|
||||||
|
import macros
|
||||||
|
|
||||||
|
type
|
||||||
|
Vehicle[T] = object of RootObj
|
||||||
|
tire: T
|
||||||
|
Car[T] = object of Vehicle[T]
|
||||||
|
Bike[T] = object of Vehicle[T]
|
||||||
|
|
||||||
|
macro peek(n: typed): untyped =
|
||||||
|
echo getTypeImpl(n).treeRepr
|
||||||
|
echo "---------"
|
||||||
|
|
||||||
|
var v = Vehicle[int](tire: 3)
|
||||||
|
var c = Car[int](tire: 4)
|
||||||
|
var b = Bike[int](tire: 2)
|
||||||
|
|
||||||
|
peek([c, b, v])
|
||||||
|
peek([v, c, b])
|
||||||
Loading…
Add table
Add a link
Reference in a new issue