From 9134dd3c0bc9a30a4c9fbaf2d714ee56fd2f5ecc Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Wed, 3 Sep 2025 20:53:39 +0200 Subject: [PATCH] `typeassert` `Expr` constructor return value Type stability fix: makes the return value of the `Expr` constructor method infer as `Expr`. Not sure if this could be fixed at a deeper level of the call stack instead. Works around issue JuliaLang/julia#42372 in the case of this method. --- src/integration/expr.jl | 2 +- test/expr.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integration/expr.jl b/src/integration/expr.jl index da9c67c9..1b8a86a6 100644 --- a/src/integration/expr.jl +++ b/src/integration/expr.jl @@ -668,4 +668,4 @@ function to_expr(node) return fixup_Expr_child(wrapper_head, node_to_expr(node, source, txtbuf, UInt32(txtbuf_offset)), false) end -Base.Expr(node::SyntaxNode) = to_expr(node) +Base.Expr(node::SyntaxNode) = to_expr(node)::Expr diff --git a/test/expr.jl b/test/expr.jl index d7547848..595a1d99 100644 --- a/test/expr.jl +++ b/test/expr.jl @@ -838,6 +838,6 @@ end @testset "SyntaxNode->Expr conversion" begin src = repeat('a', 1000) * '\n' * "@hi" - @test Expr(parsestmt(SyntaxNode, SubString(src, 1001:lastindex(src)))) == + @test (@inferred Expr(parsestmt(SyntaxNode, SubString(src, 1001:lastindex(src))))) == Expr(:macrocall, Symbol("@hi"), LineNumberNode(2)) end