@@ -293,74 +293,83 @@ function _extend_operators(operators, skip_user_operators, kws, __module__::Modu
293293 unary_ex = _extend_unary_operator (f_inside, f_outside, type_requirements, internal)
294294 # ! format: off
295295 return quote
296- local $ type_requirements, $ build_converters, $ binary_exists, $ unary_exists
296+ # Initialize locals so static analyzers (JET) don't treat them as undefined
297+ # when control-flow goes through closures/locks.
298+ local $ type_requirements = Any
299+ local $ build_converters = false
300+ local $ binary_exists = Dict {Function,Bool} ()
301+ local $ unary_exists = Dict {Function,Bool} ()
302+
297303 $ (_validate_no_ambiguous_broadcasts)($ operators)
298304 lock ($ LATEST_LOCK) do
299- if isa ($ operators, $ OperatorEnum)
300- $ type_requirements = $ (on_type == nothing ? Number : on_type)
301- $ build_converters = $ (on_type == nothing )
302- if ! haskey ($ (ALREADY_DEFINED_BINARY_OPERATORS). operator_enum, $ type_requirements)
303- $ (ALREADY_DEFINED_BINARY_OPERATORS). operator_enum[$ type_requirements] = Dict {Function,Bool} ()
304- end
305- if ! haskey ($ (ALREADY_DEFINED_UNARY_OPERATORS). operator_enum, $ type_requirements)
306- $ (ALREADY_DEFINED_UNARY_OPERATORS). operator_enum[$ type_requirements] = Dict {Function,Bool} ()
307- end
308- $ binary_exists = $ (ALREADY_DEFINED_BINARY_OPERATORS). operator_enum[$ type_requirements]
309- $ unary_exists = $ (ALREADY_DEFINED_UNARY_OPERATORS). operator_enum[$ type_requirements]
310- else
311- $ type_requirements = $ (on_type == nothing ? Any : on_type)
312- $ build_converters = false
313- if ! haskey ($ (ALREADY_DEFINED_BINARY_OPERATORS). generic_operator_enum, $ type_requirements)
314- $ (ALREADY_DEFINED_BINARY_OPERATORS). generic_operator_enum[$ type_requirements] = Dict {Function,Bool} ()
315- end
316- if ! haskey ($ (ALREADY_DEFINED_UNARY_OPERATORS). generic_operator_enum, $ type_requirements)
317- $ (ALREADY_DEFINED_UNARY_OPERATORS). generic_operator_enum[$ type_requirements] = Dict {Function,Bool} ()
318- end
319- $ binary_exists = $ (ALREADY_DEFINED_BINARY_OPERATORS). generic_operator_enum[$ type_requirements]
320- $ unary_exists = $ (ALREADY_DEFINED_UNARY_OPERATORS). generic_operator_enum[$ type_requirements]
321- end
322- if $ (empty_old_operators)
323- # Trigger errors if operators are not yet defined:
324- empty! ($ (LATEST_BINARY_OPERATOR_MAPPING))
325- empty! ($ (LATEST_UNARY_OPERATOR_MAPPING))
326- end
327- for (op, func) in enumerate ($ (operators). binops)
328- local ($ f_outside, $ f_inside) = $ (_unpack_broadcast_function)(func)
329- local $ skip = false
330- if isdefined (Base, $ f_outside)
331- $ f_outside = :(Base.$ ($ f_outside))
332- elseif $ (skip_user_operators)
333- $ skip = true
305+ if isa ($ operators, $ OperatorEnum)
306+ $ type_requirements = $ (on_type == nothing ? Number : on_type)
307+ $ build_converters = $ (on_type == nothing )
308+ if ! haskey ($ (ALREADY_DEFINED_BINARY_OPERATORS). operator_enum, $ type_requirements)
309+ $ (ALREADY_DEFINED_BINARY_OPERATORS). operator_enum[$ type_requirements] = Dict {Function,Bool} ()
310+ end
311+ if ! haskey ($ (ALREADY_DEFINED_UNARY_OPERATORS). operator_enum, $ type_requirements)
312+ $ (ALREADY_DEFINED_UNARY_OPERATORS). operator_enum[$ type_requirements] = Dict {Function,Bool} ()
313+ end
314+ $ binary_exists = $ (ALREADY_DEFINED_BINARY_OPERATORS). operator_enum[$ type_requirements]
315+ $ unary_exists = $ (ALREADY_DEFINED_UNARY_OPERATORS). operator_enum[$ type_requirements]
334316 else
335- $ f_outside = :($ ($ __module__). $ ($ f_outside))
317+ $ type_requirements = $ (on_type == nothing ? Any : on_type)
318+ $ build_converters = false
319+ if ! haskey ($ (ALREADY_DEFINED_BINARY_OPERATORS). generic_operator_enum, $ type_requirements)
320+ $ (ALREADY_DEFINED_BINARY_OPERATORS). generic_operator_enum[$ type_requirements] = Dict {Function,Bool} ()
321+ end
322+ if ! haskey ($ (ALREADY_DEFINED_UNARY_OPERATORS). generic_operator_enum, $ type_requirements)
323+ $ (ALREADY_DEFINED_UNARY_OPERATORS). generic_operator_enum[$ type_requirements] = Dict {Function,Bool} ()
324+ end
325+ $ binary_exists = $ (ALREADY_DEFINED_BINARY_OPERATORS). generic_operator_enum[$ type_requirements]
326+ $ unary_exists = $ (ALREADY_DEFINED_UNARY_OPERATORS). generic_operator_enum[$ type_requirements]
336327 end
337- $ (LATEST_BINARY_OPERATOR_MAPPING)[func] = op
338- $ skip && continue
339- # Avoid redefining methods:
340- if ! haskey ($ unary_exists, func)
341- eval ($ binary_ex)
342- $ (unary_exists)[func] = true
328+
329+ if $ (empty_old_operators)
330+ # Trigger errors if operators are not yet defined:
331+ empty! ($ (LATEST_BINARY_OPERATOR_MAPPING))
332+ empty! ($ (LATEST_UNARY_OPERATOR_MAPPING))
343333 end
344- end
345- for (op, func) in enumerate ($ (operators). unaops)
346- local ($ f_outside, $ f_inside) = $ (_unpack_broadcast_function)(func)
347- local $ skip = false
348- if isdefined (Base, $ f_outside)
349- $ f_outside = :(Base.$ ($ f_outside))
350- elseif $ (skip_user_operators)
351- $ skip = true
352- else
353- $ f_outside = :($ ($ __module__). $ ($ f_outside))
334+
335+ for (op, func) in enumerate ($ (operators). binops)
336+ local ($ f_outside, $ f_inside) = $ (_unpack_broadcast_function)(func)
337+ local $ skip = false
338+ if isdefined (Base, $ f_outside)
339+ $ f_outside = :(Base.$ ($ f_outside))
340+ elseif $ (skip_user_operators)
341+ $ skip = true
342+ else
343+ $ f_outside = :($ ($ __module__). $ ($ f_outside))
344+ end
345+ $ (LATEST_BINARY_OPERATOR_MAPPING)[func] = op
346+ $ skip && continue
347+ # Avoid redefining methods:
348+ if ! haskey ($ unary_exists, func)
349+ eval ($ binary_ex)
350+ $ (unary_exists)[func] = true
351+ end
354352 end
355- $ (LATEST_UNARY_OPERATOR_MAPPING)[func] = op
356- $ skip && continue
357- # Avoid redefining methods:
358- if ! haskey ($ binary_exists, func)
359- eval ($ unary_ex)
360- $ (binary_exists)[func] = true
353+
354+ for (op, func) in enumerate ($ (operators). unaops)
355+ local ($ f_outside, $ f_inside) = $ (_unpack_broadcast_function)(func)
356+ local $ skip = false
357+ if isdefined (Base, $ f_outside)
358+ $ f_outside = :(Base.$ ($ f_outside))
359+ elseif $ (skip_user_operators)
360+ $ skip = true
361+ else
362+ $ f_outside = :($ ($ __module__). $ ($ f_outside))
363+ end
364+ $ (LATEST_UNARY_OPERATOR_MAPPING)[func] = op
365+ $ skip && continue
366+ # Avoid redefining methods:
367+ if ! haskey ($ binary_exists, func)
368+ eval ($ unary_ex)
369+ $ (binary_exists)[func] = true
370+ end
361371 end
362372 end
363- end
364373 end
365374 # ! format: on
366375end
0 commit comments