Skip to content

Commit ab6f09a

Browse files
committed
Ensure we generate functions for both generic and regular operator enum
1 parent e6d4b24 commit ab6f09a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/OperatorEnumConstruction.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ const LATEST_OPERATORS = Ref{Union{Nothing,AbstractOperatorEnum}}(nothing)
2121
const LATEST_OPERATORS_TYPE = Ref{AvailableOperatorTypes}(IsNothing)
2222
const LATEST_UNARY_OPERATOR_MAPPING = Dict{Function,Int}()
2323
const LATEST_BINARY_OPERATOR_MAPPING = Dict{Function,Int}()
24-
const ALREADY_DEFINED_UNARY_OPERATORS = Dict{Function,Bool}()
25-
const ALREADY_DEFINED_BINARY_OPERATORS = Dict{Function,Bool}()
24+
const ALREADY_DEFINED_UNARY_OPERATORS = (;
25+
operator_enum=Dict{Function,Bool}(), generic_operator_enum=Dict{Function,Bool}()
26+
)
27+
const ALREADY_DEFINED_BINARY_OPERATORS = (;
28+
operator_enum=Dict{Function,Bool}(), generic_operator_enum=Dict{Function,Bool}()
29+
)
2630

2731
function Base.show(io::IO, tree::Node)
2832
latest_operators_type = LATEST_OPERATORS_TYPE.x
@@ -170,12 +174,18 @@ function _extend_operators(operators, skip_user_operators, __module__::Module)
170174
return quote
171175
local type_requirements
172176
local build_converters
177+
local binary_exists
178+
local unary_exists
173179
if isa($operators, OperatorEnum)
174180
type_requirements = Number
175181
build_converters = true
182+
binary_exists = $(ALREADY_DEFINED_BINARY_OPERATORS).operator_enum
183+
unary_exists = $(ALREADY_DEFINED_UNARY_OPERATORS).operator_enum
176184
else
177185
type_requirements = Any
178186
build_converters = false
187+
binary_exists = $(ALREADY_DEFINED_BINARY_OPERATORS).generic_operator_enum
188+
unary_exists = $(ALREADY_DEFINED_UNARY_OPERATORS).generic_operator_enum
179189
end
180190
# Trigger errors if operators are not yet defined:
181191
empty!($(LATEST_BINARY_OPERATOR_MAPPING))
@@ -193,9 +203,9 @@ function _extend_operators(operators, skip_user_operators, __module__::Module)
193203
$(LATEST_BINARY_OPERATOR_MAPPING)[func] = op
194204
skip && continue
195205
# Avoid redefining methods:
196-
if !haskey($(ALREADY_DEFINED_UNARY_OPERATORS), func)
206+
if !haskey(unary_exists, func)
197207
eval($binary_ex)
198-
$(ALREADY_DEFINED_UNARY_OPERATORS)[func] = true
208+
unary_exists[func] = true
199209
end
200210
end
201211
for (op, func) in enumerate($(operators).unaops)
@@ -211,9 +221,9 @@ function _extend_operators(operators, skip_user_operators, __module__::Module)
211221
$(LATEST_UNARY_OPERATOR_MAPPING)[func] = op
212222
skip && continue
213223
# Avoid redefining methods:
214-
if !haskey($(ALREADY_DEFINED_BINARY_OPERATORS), func)
224+
if !haskey(binary_exists, func)
215225
eval($unary_ex)
216-
$(ALREADY_DEFINED_BINARY_OPERATORS)[func] = true
226+
binary_exists[func] = true
217227
end
218228
end
219229
end

0 commit comments

Comments
 (0)