mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
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:
@@ -13,5 +13,20 @@ type
|
||||
hd1: float
|
||||
PA* = ref A
|
||||
PtA* = ptr A
|
||||
E*[T] = object
|
||||
he1: int
|
||||
FSub[T1, T2] = object
|
||||
h3: T1
|
||||
h4: T2
|
||||
F*[T1, T2] = ref FSub[T1, T2]
|
||||
G*[T] = ref E[T]
|
||||
H3*[T] = object
|
||||
h5: T
|
||||
H2*[T] = H3[T]
|
||||
H1*[T] = ref H2[T]
|
||||
H*[T] = H1[T]
|
||||
|
||||
type BAalias* = typeof(B.default)
|
||||
# typeof is not a transparent abstraction, creates a `tyAlias`
|
||||
|
||||
proc initB*(): B = B()
|
||||
|
||||
@@ -36,6 +36,55 @@ template main =
|
||||
let c = C(c0: 1, hc1: 2)
|
||||
c.hc1 == 2
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
not compiles(E[int](he1: 1))
|
||||
privateAccess E[int]
|
||||
var e = E[int](he1: 1)
|
||||
e.he1 == 1
|
||||
e.he1 = 2
|
||||
e.he1 == 2
|
||||
e.he1 += 3
|
||||
e.he1 == 5
|
||||
# xxx caveat: this currently compiles but in future, we may want
|
||||
# to make `privateAccess E[int]` only affect a specific instantiation;
|
||||
# note that `privateAccess E` does work to cover all instantiations.
|
||||
var e2 = E[float](he1: 1)
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
not compiles(E[int](he1: 1))
|
||||
privateAccess E
|
||||
var e = E[int](he1: 1)
|
||||
e.he1 == 1
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
not compiles(F[int, int](h3: 1))
|
||||
privateAccess F[int, int]
|
||||
var e = F[int, int](h3: 1)
|
||||
e.h3 == 1
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
not compiles(F[int, int](h3: 1))
|
||||
privateAccess F[int, int].default[].typeof
|
||||
var e = F[int, int](h3: 1)
|
||||
e.h3 == 1
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
var a = G[int]()
|
||||
var b = a.addr
|
||||
privateAccess b.type
|
||||
discard b.he1
|
||||
discard b[][].he1
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
privateAccess H[int]
|
||||
var a = H[int](h5: 2)
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
privateAccess PA
|
||||
@@ -44,6 +93,13 @@ template main =
|
||||
pa.ha1 = 3
|
||||
pa.ha1 == 3
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
var b = BAalias()
|
||||
not compiles(b.hb1)
|
||||
privateAccess BAalias
|
||||
discard b.hb1
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
var a = A(a0: 1)
|
||||
|
||||
Reference in New Issue
Block a user