File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,9 @@ julia> sval[]
38
38
implementation is available from the package ScopedValues.jl.
39
39
"""
40
40
mutable struct ScopedValue{T}
41
- const has_default:: Bool
41
+ # NOTE this struct must be defined as mutable one since it's used as a key of
42
+ # `ScopeStorage` dictionary and thus needs object identity
43
+ const has_default:: Bool # this field is necessary since isbitstype `default` field may be initialized with undefined value
42
44
const default:: T
43
45
ScopedValue {T} () where T = new (false )
44
46
ScopedValue {T} (val) where T = new {T} (true , val)
Original file line number Diff line number Diff line change @@ -4,13 +4,18 @@ import Base: ScopedValues
4
4
@testset " errors" begin
5
5
@test ScopedValue {Float64} (1 )[] == 1.0
6
6
@test_throws InexactError ScopedValue {Int} (1.5 )
7
- val = ScopedValue (1 )
8
- @test_throws MethodError val[] = 2
9
- with () do
7
+ let val = ScopedValue (1 )
10
8
@test_throws MethodError val[] = 2
9
+ with () do
10
+ @test_throws MethodError val[] = 2
11
+ end
12
+ end
13
+ let val = ScopedValue {String} ()
14
+ @test_throws KeyError val[]
15
+ end
16
+ let val = ScopedValue {Int} ()
17
+ @test_throws KeyError val[]
11
18
end
12
- val = ScopedValue {Int} ()
13
- @test_throws KeyError val[]
14
19
@test_throws MethodError ScopedValue ()
15
20
end
16
21
You can’t perform that action at this time.
0 commit comments