Skip to content

Commit 082d5b9

Browse files
committed
Type stability for variable names
1 parent d505a2f commit 082d5b9

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/OperatorEnumConstruction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ALREADY_DEFINED_UNARY_OPERATORS = (;
2727
const ALREADY_DEFINED_BINARY_OPERATORS = (;
2828
operator_enum=Dict{Function,Bool}(), generic_operator_enum=Dict{Function,Bool}()
2929
)
30-
const LATEST_VARIABLE_NAMES = Ref{Union{Nothing,Vector{String}}}(nothing)
30+
const LATEST_VARIABLE_NAMES = Ref{Vector{String}}(String[])
3131

3232
function Base.show(io::IO, tree::Node)
3333
latest_operators_type = LATEST_OPERATORS_TYPE.x

test/test_print.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ end
100100
end
101101

102102
@testset "Test variable names" begin
103-
operators = OperatorEnum(;
104-
binary_operators=[+, *, /, -], unary_operators=[cos, sin],
105-
)
103+
operators = OperatorEnum(; binary_operators=[+, *, /, -], unary_operators=[cos, sin])
106104
@extend_operators operators
107105
x1, x2, x3 = [Node(Float64; feature=i) for i in 1:3]
108-
DynamicExpressions.OperatorEnumConstructionModule.LATEST_VARIABLE_NAMES.x = ["k1", "k2", "k3"]
106+
DynamicExpressions.OperatorEnumConstructionModule.LATEST_VARIABLE_NAMES.x = [
107+
"k1", "k2", "k3"
108+
]
109109
tree = x1 * x2 + x3
110110
@test string(tree) == "((k1 * k2) + k3)"
111-
DynamicExpressions.OperatorEnumConstructionModule.LATEST_VARIABLE_NAMES.x = nothing
111+
empty!(DynamicExpressions.OperatorEnumConstructionModule.LATEST_VARIABLE_NAMES.x)
112112
@test string(tree) == "((x1 * x2) + x3)"
113+
# Check if we can pass the wrong number of variable names:
114+
DynamicExpressions.OperatorEnumConstructionModule.LATEST_VARIABLE_NAMES.x = ["k1"]
115+
@test string(tree) == "((k1 * x2) + x3)"
116+
empty!(DynamicExpressions.OperatorEnumConstructionModule.LATEST_VARIABLE_NAMES.x)
113117
end

0 commit comments

Comments
 (0)