Skip to content

Commit 1d61192

Browse files
committed
fix: convert should check degree
1 parent bae7063 commit 1d61192

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/base.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,15 @@ using `convert(T1, tree.val)` at constant nodes.
529529
"""
530530
function convert(
531531
::Type{N1}, tree::N2
532-
) where {T1,T2,N1<:AbstractExpressionNode{T1},N2<:AbstractExpressionNode{T2}}
532+
) where {T1,T2,D1,D2,N1<:AbstractExpressionNode{T1,D1},N2<:AbstractExpressionNode{T2,D2}}
533533
if N1 === N2
534534
return tree
535535
end
536+
if D1 !== D2
537+
throw(
538+
ArgumentError("Cannot convert $N2 to $N1 because they have different degrees.")
539+
)
540+
end
536541
return tree_mapreduce(
537542
Base.Fix1(leaf_convert, N1),
538543
identity,
@@ -542,6 +547,11 @@ function convert(
542547
)
543548
# TODO: Need to allow user to overload this!
544549
end
550+
function convert(
551+
::Type{N1}, tree::N2
552+
) where {T1,T2,D,N1<:AbstractExpressionNode{T1},N2<:AbstractExpressionNode{T2,D}}
553+
return convert(with_max_degree(N1, Val(D)), tree)
554+
end
545555
function convert(
546556
::Type{N1}, tree::N2
547557
) where {T2,N1<:AbstractExpressionNode,N2<:AbstractExpressionNode{T2}}

0 commit comments

Comments
 (0)