From 6b8ef313419cbfbe8d5554e85e1169df7a3158ce Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 7 Oct 2024 02:31:59 -0400 Subject: [PATCH] Fix no-arg `ScopedValues.@with` within a scope (#56019) Fixes https://github.com/JuliaLang/julia/issues/56017 (cherry picked from commit 57e3c9e4bfd2bc3d54a4923066ed2c3f087b1311) --- base/scopedvalues.jl | 2 ++ test/scopedvalues.jl | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/base/scopedvalues.jl b/base/scopedvalues.jl index 6ccd4687c5c65..39e3c2c076718 100644 --- a/base/scopedvalues.jl +++ b/base/scopedvalues.jl @@ -85,6 +85,8 @@ struct Scope values::ScopeStorage end +Scope(scope::Scope) = scope + function Scope(parent::Union{Nothing, Scope}, key::ScopedValue{T}, value) where T val = convert(T, value) if parent === nothing diff --git a/test/scopedvalues.jl b/test/scopedvalues.jl index 3af6a3f065c8b..f3cd5101d0c03 100644 --- a/test/scopedvalues.jl +++ b/test/scopedvalues.jl @@ -135,6 +135,12 @@ end @test sval[] == 1 @test sval_float[] == 1.0 end + @with sval=>2 sval_float=>2.0 begin + @with begin + @test sval[] == 2 + @test sval_float[] == 2.0 + end + end end @testset "isassigned" begin