mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
Fixed borrowing dot from aliases (#18854)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user