Skip to content

Commit 8916dd3

Browse files
committed
Give an error message on invalid direct access to :scope field
1 parent 1af57c5 commit 8916dd3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

base/task.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,20 @@ end
180180
elseif field === :exception
181181
# TODO: this field name should be deprecated in 2.0
182182
return t._isexception ? t.result : nothing
183+
elseif field === :scope
184+
error("Querying `scope` is disallowed. Use `current_scope` instead.")
183185
else
184186
return getfield(t, field)
185187
end
186188
end
187189

190+
@inline function setproperty!(t::Task, field::Symbol, @nospecialize(v))
191+
if field === :scope
192+
istaskstarted(t) && error("Setting scope on a started task directly is disallowed.")
193+
end
194+
return @invoke setproperty!(t::Any, field, v)
195+
end
196+
188197
"""
189198
istaskdone(t::Task) -> Bool
190199

0 commit comments

Comments
 (0)