Skip to content

Commit

Permalink
add some comments about ScopedValue implementation (#52372)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Dec 3, 2023
1 parent 641f717 commit 3e4b386
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion base/scopedvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ julia> sval[]
implementation is available from the package ScopedValues.jl.
"""
mutable struct ScopedValue{T}
const has_default::Bool
# NOTE this struct must be defined as mutable one since it's used as a key of
# `ScopeStorage` dictionary and thus needs object identity
const has_default::Bool # this field is necessary since isbitstype `default` field may be initialized with undefined value
const default::T
ScopedValue{T}() where T = new(false)
ScopedValue{T}(val) where T = new{T}(true, val)
Expand Down
15 changes: 10 additions & 5 deletions test/scopedvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import Base: ScopedValues
@testset "errors" begin
@test ScopedValue{Float64}(1)[] == 1.0
@test_throws InexactError ScopedValue{Int}(1.5)
val = ScopedValue(1)
@test_throws MethodError val[] = 2
with() do
let val = ScopedValue(1)
@test_throws MethodError val[] = 2
with() do
@test_throws MethodError val[] = 2
end
end
let val = ScopedValue{String}()
@test_throws KeyError val[]
end
let val = ScopedValue{Int}()
@test_throws KeyError val[]
end
val = ScopedValue{Int}()
@test_throws KeyError val[]
@test_throws MethodError ScopedValue()
end

Expand Down

4 comments on commit 3e4b386

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

@vtjnash
Copy link
Member

@vtjnash vtjnash commented on 3e4b386 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Please sign in to comment.