Skip to content

Commit 73506ed

Browse files
authored
add a missing type assert to OncePerTask callable (#57356)
also test that the difference `OncePerX` infer
1 parent 4206080 commit 73506ed

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

base/lock.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,4 +933,6 @@ mutable struct OncePerTask{T, F} <: Function
933933
OncePerTask{T,F}(initializer::F) where {T, F} = new{T,F}(initializer)
934934
OncePerTask(initializer) = new{Base.promote_op(initializer), typeof(initializer)}(initializer)
935935
end
936-
@inline (once::OncePerTask)() = get!(once.initializer, task_local_storage(), once)
936+
@inline function (once::OncePerTask{T})() where {T}
937+
get!(once.initializer, task_local_storage(), once)::T
938+
end

test/threads.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ end
439439

440440
let once = OncePerProcess(() -> return [nothing])
441441
@test typeof(once) <: OncePerProcess{Vector{Nothing}}
442-
x = once()
442+
x = @inferred once()
443443
@test x === once()
444444
@atomic once.state = 0xff
445445
@test_throws ErrorException("invalid state for OncePerProcess") once()
@@ -456,7 +456,7 @@ let e = Base.Event(true),
456456
started = Channel{Int16}(Inf),
457457
finish = Channel{Nothing}(Inf),
458458
exiting = Channel{Nothing}(Inf),
459-
starttest2 = Event(),
459+
starttest2 = Base.Event(),
460460
once = OncePerThread() do
461461
push!(started, threadid())
462462
take!(finish)
@@ -468,7 +468,7 @@ let e = Base.Event(true),
468468
@test typeof(once) <: OncePerThread{Vector{Nothing}}
469469
push!(finish, nothing)
470470
@test_throws ArgumentError once[0]
471-
x = once()
471+
x = @inferred once()
472472
@test_throws ArgumentError once[0]
473473
@test x === once() === fetch(@async once()) === once[threadid()]
474474
@test take!(started) == threadid()
@@ -558,7 +558,7 @@ end
558558

559559
let once = OncePerTask(() -> return [nothing])
560560
@test typeof(once) <: OncePerTask{Vector{Nothing}}
561-
x = once()
561+
x = @inferred once()
562562
@test x === once() !== fetch(@async once())
563563
delete!(task_local_storage(), once)
564564
@test x !== once() === once()

0 commit comments

Comments
 (0)