make privateAccess work with generic types and generic instantiations; fix a SIGSEGV (#18260)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
5d15bd7b61
commit
7714ab468a
5 changed files with 118 additions and 15 deletions
|
|
@ -1887,6 +1887,26 @@ proc toObject*(typ: PType): PType =
|
|||
if t.kind == tyRef: t.lastSon
|
||||
else: typ
|
||||
|
||||
proc toObjectFromRefPtrGeneric*(typ: PType): PType =
|
||||
#[
|
||||
See also `toObject`.
|
||||
Finds the underlying `object`, even in cases like these:
|
||||
type
|
||||
B[T] = object f0: int
|
||||
A1[T] = ref B[T]
|
||||
A2[T] = ref object f1: int
|
||||
A3 = ref object f2: int
|
||||
A4 = object f3: int
|
||||
]#
|
||||
result = typ
|
||||
while true:
|
||||
case result.kind
|
||||
of tyGenericBody: result = result.lastSon
|
||||
of tyRef, tyPtr, tyGenericInst, tyGenericInvocation, tyAlias: result = result[0]
|
||||
# automatic dereferencing is deep, refs #18298.
|
||||
else: break
|
||||
assert result.sym != nil
|
||||
|
||||
proc isImportedException*(t: PType; conf: ConfigRef): bool =
|
||||
assert t != nil
|
||||
|
||||
|
|
|
|||
|
|
@ -457,6 +457,11 @@ proc semOld(c: PContext; n: PNode): PNode =
|
|||
localError(c.config, n[1].info, n[1].sym.name.s & " does not belong to " & getCurrOwner(c).name.s)
|
||||
result = n
|
||||
|
||||
proc semPrivateAccess(c: PContext, n: PNode): PNode =
|
||||
let t = n[1].typ[0].toObjectFromRefPtrGeneric
|
||||
c.currentScope.allowPrivateAccess.add t.sym
|
||||
result = newNodeIT(nkEmpty, n.info, getSysType(c.graph, n.info, tyVoid))
|
||||
|
||||
proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
||||
flags: TExprFlags): PNode =
|
||||
## This is the preferred code point to implement magics.
|
||||
|
|
@ -574,9 +579,6 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
|||
n[0].sym.magic = mSubU
|
||||
result = n
|
||||
of mPrivateAccess:
|
||||
var t = n[1].typ[0]
|
||||
if t.kind in {tyRef, tyPtr}: t = t[0]
|
||||
c.currentScope.allowPrivateAccess.add t.sym
|
||||
result = newNodeIT(nkEmpty, n.info, getSysType(c.graph, n.info, tyVoid))
|
||||
result = semPrivateAccess(c, n)
|
||||
else:
|
||||
result = n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue