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:
Timothee Cour 2021-06-19 11:24:46 -07:00 • committed by GitHub
commit 7714ab468a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 15 deletions

View file

@ -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