Skip to content

Commit 1f3aeb9

Browse files
committed
Add back deprecated constructors with tests
1 parent c5417ee commit 1f3aeb9

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/deprecated.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
11
import Base: @deprecate
2+
import .EquationModule: Node
23

34
@deprecate set_constants set_constants!
45
@deprecate simplify_tree simplify_tree!
6+
7+
function Node(d::Integer, c::Bool, v::T) where {T}
8+
Base.depwarn("Node(d, c, v) is deprecated. Use Node{T}(val=v) instead.", :Node)
9+
@assert d == 1
10+
@assert c == true
11+
return Node{T}(; val=v)
12+
end
13+
function Node(::Type{T}, d::Integer, c::Bool, v::_T) where {T,_T}
14+
Base.depwarn("Node(T, d, c, v) is deprecated. Use Node{T}(val=v) instead.", :Node)
15+
@assert d == 1
16+
@assert c == true
17+
return Node{T}(; val=v)
18+
end
19+
function Node(::Type{T}, d::Integer, c::Bool, ::Nothing, f::Integer) where {T}
20+
Base.depwarn(
21+
"Node(T, d, c, v, f) is deprecated. Use Node{T}(feature=f) instead.", :Node
22+
)
23+
@assert d == 1
24+
@assert c == false
25+
return Node{T}(; feature=f)
26+
end
27+
function Node(d::Integer, ::Bool, ::Nothing, ::Integer, o::Integer, l::Node)
28+
Base.depwarn(
29+
"Node(d, c, v, f, o, l) is deprecated. Use Node(operator=o, left=l) instead.", :Node
30+
)
31+
@assert d == 1
32+
return Node(; op=o, l=l)
33+
end
34+
function Node(
35+
d::Integer, ::Bool, ::Nothing, ::Integer, o::Integer, l::Node{T}, r::Node{T}
36+
) where {T}
37+
Base.depwarn(
38+
"Node(d, c, v, f, o, l, r) is deprecated. Use Node(op=o, l=l, r=r) instead.", :Node
39+
)
40+
@assert d == 2
41+
return Node(; op=o, l=l, r=r)
42+
end

test/test_deprecations.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,26 @@ for constructor in (OperatorEnum, GenericOperatorEnum)
2020
[1.0; 2.0;;]
2121
)
2222
end
23+
24+
if VERSION >= v"1.9"
25+
@test_logs (:warn, r"Node\(d, c, v\) is deprecated.*") (
26+
n = Node(1, true, 1.0 + 0im); @assert (n.val isa ComplexF64)
27+
)
28+
@test_logs (:warn, r"Node\(T, d, c, v\) is deprecated.*") (
29+
n = Node(Float32, 1, true, 1.0 + 0im); @assert (n.val isa Float32)
30+
)
31+
@test_logs (:warn, r"Node\(T, d, c, v, f\) is deprecated.*") (
32+
n = Node(Float32, 1, false, nothing, 1); @assert (n.feature == 1)
33+
)
34+
@test_logs (:warn, r"Node\(d, c, v, f, o, l\) is deprecated.*") (
35+
x1 = Node(; feature=1);
36+
n = Node(1, true, nothing, 1, 3, x1);
37+
@assert (n.op == 3 && n.l === x1)
38+
)
39+
@test_logs (:warn, r"Node\(d, c, v, f, o, l, r\) is deprecated.*") (
40+
x1 = Node(; feature=1);
41+
x2 = Node(; feature=2);
42+
n = Node(2, true, nothing, 1, 1, x1, x2);
43+
@assert (n.op == 1 && n.l === x1 && n.r === x2)
44+
)
45+
end

0 commit comments

Comments
 (0)