Skip to content

Commit 867dab6

Browse files
committed
test: fix children call in ReadOnlyNode
1 parent 5f647ff commit 867dab6

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Interfaces.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ function _check_get_metadata(ex::AbstractExpression)
7070
new_ex = with_metadata(ex, get_metadata(ex))
7171
return new_ex == ex && new_ex isa typeof(ex)
7272
end
73-
function _check_get_tree(ex::AbstractExpression{T,N}) where {T,D,N<:AbstractExpressionNode{T,D}}
73+
function _check_get_tree(
74+
ex::AbstractExpression{T,N}
75+
) where {T,D,N<:AbstractExpressionNode{T,D}}
7476
return get_tree(ex) isa N || get_tree(ex) isa AbstractReadOnlyNode{T,D,N}
7577
end
7678
function _check_get_operators(ex::AbstractExpression)

src/Node.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ end
206206
@make_accessors Node
207207
@make_accessors GraphNode
208208

209+
@inline children(node::AbstractNode) = node.children
209210
@inline function children(node::AbstractNode, ::Val{n}) where {n}
210-
cs = node.children
211+
cs = children(node)
211212
return ntuple(i -> cs[i][], Val(n))
212213
end
213214

src/ReadOnlyNode.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ReadOnlyNodeModule
22

33
using ..NodeModule: AbstractExpressionNode, Node
4-
import ..NodeModule: default_allocator, with_type_parameters, constructorof
4+
import ..NodeModule: default_allocator, with_type_parameters, constructorof, children
55

66
abstract type AbstractReadOnlyNode{T,D,N<:AbstractExpressionNode{T,D}} <:
77
AbstractExpressionNode{T,D} end
@@ -16,11 +16,14 @@ constructorof(::Type{<:ReadOnlyNode}) = ReadOnlyNode
1616
@inline function Base.getproperty(n::AbstractReadOnlyNode, s::Symbol)
1717
out = getproperty(getfield(n, :_inner), s)
1818
if out isa AbstractExpressionNode
19-
return constructorof(typeof(n))(out)
19+
return ReadOnlyNode(out)
2020
else
2121
return out
2222
end
2323
end
24+
@inline function children(node::AbstractReadOnlyNode)
25+
return map(ReadOnlyNode, children(node))
26+
end
2427
function Base.setproperty!(::AbstractReadOnlyNode, ::Symbol, v)
2528
return error("Cannot set properties on a ReadOnlyNode")
2629
end

0 commit comments

Comments
 (0)