Skip to content

Commit 76655d3

Browse files
committed
Clean up type parameters in constructors
1 parent 627091f commit 76655d3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Equation.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ constructorof(::Type{N}) where {N<:AbstractNode} = Base.typename(N).wrapper
192192
constructorof(::Type{<:Node}) = Node
193193
constructorof(::Type{<:GraphNode}) = GraphNode
194194

195+
function with_type_parameters(::Type{N}, ::Type{T}) where {N<:AbstractExpressionNode,T}
196+
return constructorof(N){T}
197+
end
198+
with_type_parameters(::Type{<:Node}, ::Type{T}) where {T} = Node{T}
199+
with_type_parameters(::Type{<:GraphNode}, ::Type{T}) where {T} = GraphNode{T}
200+
195201
"""Trait declaring whether nodes share children or not."""
196202
preserve_sharing(::Type{<:AbstractNode}) = false
197203
preserve_sharing(::Type{<:Node}) = false
@@ -220,18 +226,24 @@ function (::Type{N})(
220226
op::Integer, l::AbstractExpressionNode{T}
221227
) where {T,N<:AbstractExpressionNode}
222228
@assert l isa N
229+
if !(N isa UnionAll)
230+
@warn "Ignoring specified type parameters in binary operator constructor."
231+
end
223232
return constructorof(N)(1, false, nothing, 0, op, l)
224233
end
225234
function (::Type{N})(
226235
op::Integer, l::AbstractExpressionNode{T1}, r::AbstractExpressionNode{T2}
227236
) where {T1,T2,N<:AbstractExpressionNode}
228237
@assert l isa N && r isa N
238+
if !(N isa UnionAll)
239+
@warn "Ignoring specified type parameters in binary operator constructor."
240+
end
229241
# Get highest type:
230242
if T1 != T2
231243
T = promote_type(T1, T2)
232244
# TODO: This might slow things down
233-
l = convert(N{T}, l)
234-
r = convert(N{T}, r)
245+
l = convert(with_type_parameters(N, T), l)
246+
r = convert(with_type_parameters(N, T), r)
235247
end
236248
return constructorof(N)(2, false, nothing, 0, op, l, r)
237249
end

0 commit comments

Comments
 (0)