Fixed borrowing dot from aliases (#18854)

This commit is contained in:
Jason Beetham
2021-09-16 00:48:58 -06:00
committed by GitHub
parent cebf7cdc1e
commit f8e185fec0
2 changed files with 39 additions and 3 deletions

View File

@@ -1280,7 +1280,7 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode =
if p != nil and p.selfSym != nil:
var ty = skipTypes(p.selfSym.typ, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef,
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
if ty.kind == tyObject:
while true:
@@ -1412,7 +1412,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
ty = ty.lastSon
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
if ty.kind == tyObject:
while true:

View File

@@ -52,4 +52,40 @@ block: #14449
c.foo = 42
assert a.foo == 300
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