Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ScopedValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ Base.eltype(::ScopedValue{T}) where {T} = T
"""
isassigned(val::ScopedValue)

Test if the ScopedValue has a default value.
Test if the ScopedValue has an assigned value.
"""
Base.isassigned(val::ScopedValue) = val.has_default
function Base.isassigned(val::ScopedValue)
val.has_default && return true
scope = current_scope()::Union{Scope, Nothing}
scope === nothing && return false
return haskey((scope::Scope).values, val)
end

const ScopeStorage = HAMT{ScopedValue, Any}

Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ end
@test ret == 1.23
end

const sval_uninitialized = ScopedValue{Int}()

@testset "isassigned()" begin
@test !isassigned(sval_uninitialized)
@with sval_uninitialized => 42 @test isassigned(sval_uninitialized)
end

@testset "ScopedThunk" begin
function check_svals()
@test sval[] == 8
Expand Down
Loading