From 06de99ef626fd15b8147328a716c9a1ffb1fc712 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 2 Nov 2023 04:44:49 -0400 Subject: [PATCH] Make Scope immutable (#51976) Addresses keno review comment in https://github.com/JuliaLang/julia/pull/50958#discussion_r1378513975 --- base/scopedvalues.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/scopedvalues.jl b/base/scopedvalues.jl index 4c46809e75ffe..94491294c798a 100644 --- a/base/scopedvalues.jl +++ b/base/scopedvalues.jl @@ -56,7 +56,7 @@ Base.isassigned(val::ScopedValue) = val.has_default const ScopeStorage = Base.PersistentDict{ScopedValue, Any} -mutable struct Scope +struct Scope values::ScopeStorage end @@ -114,15 +114,15 @@ function get(val::ScopedValue{T}) where {T} # Inline current_scope to avoid doing the type assertion twice. scope = current_task().scope if scope === nothing - isassigned(val) && return Some(val.default) + isassigned(val) && return Some{T}(val.default) return nothing end scope = scope::Scope if isassigned(val) - return Some(Base.get(scope.values, val, val.default)::T) + return Some{T}(Base.get(scope.values, val, val.default)::T) else v = Base.get(scope.values, val, novalue) - v === novalue || return Some(v::T) + v === novalue || return Some{T}(v::T) end return nothing end