File tree 3 files changed +43
-0
lines changed
3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -1324,6 +1324,7 @@ export
1324
1324
1325
1325
# nullable types
1326
1326
isnull,
1327
+ unsafe_get,
1327
1328
1328
1329
# Macros
1329
1330
# parser internal
Original file line number Diff line number Diff line change 61
61
62
62
get (x:: Nullable ) = x. isnull ? throw (NullException ()) : x. value
63
63
64
+ unsafe_get (x:: Nullable ) = x. value
65
+ unsafe_get (x) = x
66
+
64
67
isnull (x:: Nullable ) = x. isnull
68
+ isnull (x) = false
65
69
66
70
67
71
# # Operators
Original file line number Diff line number Diff line change @@ -161,6 +161,33 @@ for T in types
161
161
@test get (x3, zero (T)) === one (T)
162
162
end
163
163
164
+ # unsafe_get(x::Nullable)
165
+ for T in types
166
+ x1 = Nullable {T} ()
167
+ x2 = Nullable (zero (T))
168
+ x3 = Nullable (one (T))
169
+ a = rand (T)
170
+ x4 = Nullable (a)
171
+
172
+ @test isa (unsafe_get (x1), T)
173
+ @test unsafe_get (x2) === zero (T)
174
+ @test unsafe_get (x3) === one (T)
175
+ @test unsafe_get (x4) === a
176
+ end
177
+
178
+ @test_throws UndefRefError unsafe_get (Nullable ())
179
+
180
+ # unsafe_get(x)
181
+ for T in types
182
+ x2 = zero (T)
183
+ x3 = one (T)
184
+ x4 = rand (T)
185
+
186
+ @test unsafe_get (x2) === zero (T)
187
+ @test unsafe_get (x3) === one (T)
188
+ @test unsafe_get (x4) === x4
189
+ end
190
+
164
191
# isnull(x::Nullable)
165
192
for T in types
166
193
x1 = Nullable {T} ()
174
201
175
202
@test isnull (Nullable ())
176
203
204
+ # isnull(x)
205
+ for T in types
206
+ x1 = zero (T)
207
+ x2 = one (T)
208
+ x3 = rand (T)
209
+
210
+ @test isnull (x1) === false
211
+ @test isnull (x2) === false
212
+ @test isnull (x3) === false
213
+ end
214
+
177
215
# function =={S, T}(x::Nullable{S}, y::Nullable{T})
178
216
for T in types
179
217
x0 = Nullable ()
You can’t perform that action at this time.
0 commit comments