-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest1.har
203 lines (165 loc) · 3.96 KB
/
test1.har
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#### HAR
privateImport tests
(adapted from D20190821T153114)
#### m2.nim
const bar1* = 2
const bar2 = 2
####
#### m3.nim
const car1* = 2
const car2 = 2
####
#### m1.nim # imported by others
{.experimental: "allowPrivateImport".}
import ./m2
import ./m3 {.privateImport.} as m3
from ./m3 as m3Bis import nil
# export m3
doAssert car2 == 2
export car2
export m3Bis.car1
const foo0* = 2
const foo1 = bar1
const foo1Aux = 2
export foo1Aux
doAssert not declared(bar2)
doAssert not compiles(bar2)
var foo2 = 2
let foo3 = 2
type Foo4 = enum
kg1, kg2
type Foo5 = object
z1: string
z2: Foo4
z3: int
proc `z3`*(a: Foo5): auto =
a.z3 * 10
proc foo6(): auto = 2
proc foo6b*(): auto = 2
template foo7: untyped = 2
macro foo8(): untyped = discard
template foo9(a: int): untyped = discard
block:
template foo10: untyped = 2
type Foo11 = enum
kg1b, kg2b
proc foo12(): auto = 2
proc initFoo5*(z3: int): Foo5 = Foo5(z3: z3)
#### mt0.nim
{.push experimental: "allowPrivateImport".}
import ./m1 as m
doAssert compiles(foo0)
doAssert not compiles(foo1)
doAssert foo6b() == 2
doAssert car2 == 2
var f = initFoo5(z3=3)
doAssert f.z3 == 30
doAssert z3(f) == 30
#### mt1.nim
{.push experimental: "allowPrivateImport".}
import ./m1 {.privateImport.} as m
doAssert foo1 == 2
doAssert m.foo1 == 2
doAssert m.car2 == 2
doAssert car2 == 2
doAssert m.foo1Aux == 2
doAssert m.car1 == 2
## field access
var x = Foo5(z1: "foo", z2: m.kg1)
doAssert x.z1 == "foo"
var f0: Foo5
f0.z3 = 3
doAssert f0.z3 == 3
var f = initFoo5(z3=3)
doAssert f.z3 == 3
doAssert z3(f) == 30
doAssert m.z3(f) == 30
doAssert not compiles(mt1.`z3`(f)) # z3 is an imported symbol
#### mt2.nim
{.push experimental: "allowPrivateImport".}
from ./m1 {.privateImport.} as m import foo1
from ./m1 {.privateImport.} as m2 import foo7
doAssert foo1 == 2
doAssert m.foo1 == 2
doAssert m.foo2 == 2
doAssert compiles(foo1)
doAssert compiles(m.foo2)
doAssert not compiles(foo2)
doAssert not compiles(car2)
doAssert m.foo3 == 2
doAssert m.foo6() == 2
doAssert m.foo6b() == 2
doAssert foo7() == 2
doAssert m2.foo6b() == 2
doAssert not compiles(foo10())
doAssert compiles(m.Foo5)
doAssert not compiles(m.Foo11)
doAssert not compiles(m.kg1b)
doAssert not compiles(m.foo12())
## field access
var x = m.Foo5(z1: "foo", z2: m.kg1)
doAssert x.z1 == "foo"
var f0: m.Foo5
f0.z3 = 3
doAssert f0.z3 == 3
var f = m.initFoo5(z3=3)
doAssert f.z3 == 3
doAssert m.z3(f) == 30
#### mt3.nim
{.push experimental: "allowPrivateImport".}
import ./m1 {.privateImport.}
doAssert foo1 == 2
doAssert m1.foo1 == 2
doAssert not compiles(mt3.foo0) # foo0 is an imported symbol
doAssert not compiles(mt3.foo1) # ditto
#### mt4.nim
{.push experimental: "allowPrivateImport".}
import ./m1 {.privateImport.} except foo1
doAssert foo2 == 2
doAssert declared(foo2)
doAssert not compiles(foo1)
#### mt4b.nim
{.push experimental: "allowPrivateImport".}
from ./m1 {.privateImport.} as m2 import nil
doAssert not compiles(foo1)
doAssert m2.foo1 == 2
#### mt5.nim
{.push experimental: "allowPrivateImport".}
import ./m1 {.privateImport.} as m2 except foo1
doAssert foo2 == 2
doAssert not compiles(foo1)
doAssert m2.foo1 == 2
doAssert compiles(m2.foo1)
from system {.privateImport.} as s import ThisIsSystem
doAssert ThisIsSystem
doAssert s.ThisIsSystem
#### mt6.nim # declared
{.push experimental: "allowPrivateImport".}
import ./m1 {.privateImport.} as m2
doAssert compiles(foo1)
doAssert compiles(m2.foo1)
doAssert declared(foo1)
doAssert declared(m2.foo0) # public: works fine
doAssert m2.foo1 == 2
doAssert declared(m2.foo1)
doAssert not declared(m2.nonexistant)
#### mt7.nim # include
include ./m1
doAssert compiles(foo1)
doAssert compiles(mt7.foo1)
doAssert declared(foo1)
doAssert declared(mt7.foo1)
doAssert declared(mt7.foo0)
var f0: Foo5
f0.z3 = 3
doAssert f0.z3 == 3
var f = initFoo5(z3=3)
doAssert f.z3 == 3
doAssert mt7.z3(f) == 30
doAssert z3(f) == 30
#### t7b.nim # include # TODO: REMOVE
include ./m1 as m2
echo m2.foo1
#### tmain.nim
import "."/[mt0,mt1,mt2,mt3,mt4,mt4b,mt5,mt6,mt7]
####