diff --git a/TypedSyntax/Project.toml b/TypedSyntax/Project.toml index 99f35015..ee132289 100644 --- a/TypedSyntax/Project.toml +++ b/TypedSyntax/Project.toml @@ -1,7 +1,7 @@ name = "TypedSyntax" uuid = "d265eb64-f81a-44ad-a842-4247ee1503de" authors = ["Tim Holy and contributors"] -version = "1.5.1" +version = "1.5.2" [deps] CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" diff --git a/TypedSyntax/src/node.jl b/TypedSyntax/src/node.jl index 05e05754..ebcc9971 100644 --- a/TypedSyntax/src/node.jl +++ b/TypedSyntax/src/node.jl @@ -87,23 +87,25 @@ end # Recursive construction of the TypedSyntaxNode tree from the SyntaxNodeTree function addchildren!(tparent, parent, src::CodeInfo, node2ssa, symtyps, mappings) if !is_leaf(parent) - if tparent.children === nothing - tparent.children = TypedSyntaxNode[] - end for child in children(parent) typ = gettyp(node2ssa, child, src) tnode = TypedSyntaxNode(tparent, nothing, TypedSyntaxData(child.data::SyntaxData, src, typ)) if tnode.typ === nothing && (#=is_literal(child) ||=# kind(child) == K"Identifier") tnode.typ = get(symtyps, child, nothing) end + is_leaf(tparent) && (tparent.children = TypedSyntaxNode[]) push!(tparent, tnode) addchildren!(tnode, child, src, node2ssa, symtyps, mappings) end end # In `return f(args..)`, copy any types assigned to `f(args...)` up to the `[return]` node - if kind(tparent) == K"return" && !is_leaf(tparent) - childs = children(tparent) - tparent.typ = isempty(childs) ? Nothing : only(childs).typ + if kind(tparent) == K"return" + if !is_leaf(tparent) + value = only(children(tparent)) + tparent.typ = value.typ + else + tparent.typ = Nothing + end end # Replace the entry in `mappings` to be the typed node i = get(node2ssa, parent, nothing) diff --git a/test/test_codeview.jl b/test/test_codeview.jl index 181e65dd..52b7fad7 100644 --- a/test/test_codeview.jl +++ b/test/test_codeview.jl @@ -114,4 +114,10 @@ end end end +@testset "Regressions" begin + # Issue #675 + (; src, infos, codeinst, rt, exct, effects, slottypes) = cthulhu_info(NamedTuple; optimize=false) + Cthulhu.cthulhu_typed(IOBuffer(), :none, src, rt, exct, effects, codeinst; annotate_source=true) +end + end # module test_codeview