privateAccess now works with ref | ptr (#17760)

This commit is contained in:
Timothee Cour 2021-04-18 15:15:58 -07:00 • committed by GitHub
commit 0a10af5a2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 149 additions and 15 deletions

View file

@ -578,9 +578,9 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
n[0].sym.magic = mSubU
result = n
of mPrivateAccess:
let sym = n[1].typ[0].sym
assert sym != nil
c.currentScope.allowPrivateAccess.add sym
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))
else:
result = n

View file

@ -258,7 +258,9 @@ proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} =
for module in c.friendModules:
if fmoduleId == module.id: return true
if f.kind == skField:
let symObj = f.owner
var symObj = f.owner
if symObj.typ.kind in {tyRef, tyPtr}:
symObj = symObj.typ[0].sym
for scope in allScopes(c.currentScope):
for sym in scope.allowPrivateAccess:
if symObj.id == sym.id: return true