Fixed borrowing dot from aliases (#18854)
This commit is contained in:
parent
cebf7cdc1e
commit
f8e185fec0
2 changed files with 39 additions and 3 deletions
|
|
@ -1280,7 +1280,7 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode =
|
||||||
if p != nil and p.selfSym != nil:
|
if p != nil and p.selfSym != nil:
|
||||||
var ty = skipTypes(p.selfSym.typ, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef,
|
var ty = skipTypes(p.selfSym.typ, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef,
|
||||||
tyAlias, tySink, tyOwned})
|
tyAlias, tySink, tyOwned})
|
||||||
while tfBorrowDot in ty.flags: ty = ty.skipTypes({tyDistinct, tyGenericInst})
|
while tfBorrowDot in ty.flags: ty = ty.skipTypes({tyDistinct, tyGenericInst, tyAlias})
|
||||||
var check: PNode = nil
|
var check: PNode = nil
|
||||||
if ty.kind == tyObject:
|
if ty.kind == tyObject:
|
||||||
while true:
|
while true:
|
||||||
|
|
@ -1412,7 +1412,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
|
if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
|
||||||
ty = ty.lastSon
|
ty = ty.lastSon
|
||||||
ty = skipTypes(ty, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef, tyOwned, tyAlias, tySink})
|
ty = skipTypes(ty, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef, tyOwned, tyAlias, tySink})
|
||||||
while tfBorrowDot in ty.flags: ty = ty.skipTypes({tyDistinct, tyGenericInst})
|
while tfBorrowDot in ty.flags: ty = ty.skipTypes({tyDistinct, tyGenericInst, tyAlias})
|
||||||
var check: PNode = nil
|
var check: PNode = nil
|
||||||
if ty.kind == tyObject:
|
if ty.kind == tyObject:
|
||||||
while true:
|
while true:
|
||||||
|
|
|
||||||
|
|
@ -53,3 +53,39 @@ block: #14449
|
||||||
assert a.foo == 300
|
assert a.foo == 300
|
||||||
assert b.foo == 400d
|
assert b.foo == 400d
|
||||||
assert c.foo == 42d
|
assert c.foo == 42d
|
||||||
|
|
||||||
|
block: # Borrow from muliple aliasses #16666
|
||||||
|
type
|
||||||
|
AImpl = object
|
||||||
|
i: int
|
||||||
|
|
||||||
|
A = AImpl
|
||||||
|
|
||||||
|
B {.borrow: `.`.} = distinct A
|
||||||
|
C = B
|
||||||
|
D {.borrow: `.`.} = distinct C
|
||||||
|
E {.borrow: `.`.} = distinct D
|
||||||
|
|
||||||
|
let
|
||||||
|
b = default(B)
|
||||||
|
d = default(D)
|
||||||
|
e = default(E)
|
||||||
|
|
||||||
|
assert b.i == 0
|
||||||
|
assert d.i == 0
|
||||||
|
assert e.i == 0
|
||||||
|
|
||||||
|
block: # Borrow from generic alias
|
||||||
|
type
|
||||||
|
AImpl[T] = object
|
||||||
|
i: T
|
||||||
|
B[T] = AImpl[T]
|
||||||
|
C {.borrow: `.`.} = distinct B[int]
|
||||||
|
D = B[float]
|
||||||
|
E {.borrow: `.`.} = distinct D
|
||||||
|
|
||||||
|
let
|
||||||
|
c = default(C)
|
||||||
|
e = default(E)
|
||||||
|
assert c.i == int(0)
|
||||||
|
assert e.i == 0d
|
||||||
Loading…
Add table
Add a link
Reference in a new issue