privateAccess ignores non-objects (#21973)

closes #21969
This commit is contained in:
metagn
2023-06-01 06:20:08 +03:00
committed by GitHub
parent b880cdff49
commit 8f760080c5
3 changed files with 5 additions and 2 deletions

View File

@@ -2008,7 +2008,7 @@ proc toObjectFromRefPtrGeneric*(typ: PType): PType =
of tyRef, tyPtr, tyGenericInst, tyGenericInvocation, tyAlias: result = result[0]
# automatic dereferencing is deep, refs #18298.
else: break
assert result.sym != nil
# result does not have to be object type
proc isImportedException*(t: PType; conf: ConfigRef): bool =
assert t != nil

View File

@@ -524,7 +524,9 @@ proc semNewFinalize(c: PContext; n: PNode): PNode =
proc semPrivateAccess(c: PContext, n: PNode): PNode =
let t = n[1].typ[0].toObjectFromRefPtrGeneric
c.currentScope.allowPrivateAccess.add t.sym
if t.kind == tyObject:
assert t.sym != nil
c.currentScope.allowPrivateAccess.add t.sym
result = newNodeIT(nkEmpty, n.info, getSysType(c.graph, n.info, tyVoid))
proc checkDefault(c: PContext, n: PNode): PNode =

View File

@@ -277,6 +277,7 @@ proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} =
var symObj = f.owner
if symObj.typ.skipTypes({tyGenericBody, tyGenericInst, tyGenericInvocation, tyAlias}).kind in {tyRef, tyPtr}:
symObj = symObj.typ.toObjectFromRefPtrGeneric.sym
assert symObj != nil
for scope in allScopes(c.currentScope):
for sym in scope.allowPrivateAccess:
if symObj.id == sym.id: return true