diff --git a/JuliaLowering/src/compat.jl b/JuliaLowering/src/compat.jl index 391c99a624d93..8a408322b98fb 100644 --- a/JuliaLowering/src/compat.jl +++ b/JuliaLowering/src/compat.jl @@ -211,9 +211,6 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA id_inner = _insert_tree_node(graph, K"String", src; value=e) setchildren!(graph, st_id, [id_inner]) return st_id, src - elseif e isa VersionNumber - st_id = _insert_tree_node(graph, K"VERSION", src, JS.set_numeric_flags(e.minor*10); value=e) - return st_id, src elseif !(e isa Expr) # There are other kinds we could potentially back-convert (e.g. Float), # but Value should work fine. @@ -407,7 +404,7 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA st_flags |= JS.BARE_MODULE_FLAG end child_exprs = has_version ? - Any[e.args[1], e.args[2+has_version], e.args[3+has_version]] : + Any[Expr(:mod_version, e.args[1]), e.args[2+has_version], e.args[3+has_version]] : Any[e.args[2+has_version], e.args[3+has_version]] elseif e.head === :do # Expr: @@ -565,6 +562,13 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA child_exprs = nothing elseif e.head === :do_lambda st_k = K"do" + elseif e.head === :mod_version + v = e.args[1] + @assert v isa VersionNumber + st_k = K"VERSION" + st_flags = JS.set_numeric_flags(v.minor*10) + st_attrs[:value] = v + child_exprs = nothing end #--------------------------------------------------------------------------- diff --git a/JuliaLowering/src/macro_expansion.jl b/JuliaLowering/src/macro_expansion.jl index 708aed4e14fce..3015101bb239a 100644 --- a/JuliaLowering/src/macro_expansion.jl +++ b/JuliaLowering/src/macro_expansion.jl @@ -325,6 +325,13 @@ function expand_macro(ctx, ex) # Compat: attempt to invoke an old-style macro if there's no applicable # method for new-style macro arguments. macro_args = Any[macro_loc, ctx.scope_layers[1].mod] + + if length(raw_args) >= 1 && kind(raw_args[1]) === K"VERSION" + # Hack: see jl_invoke_julia_macro. We may see an extra argument + # depending on who parsed this macrocall. + macro_args[1] = Core.MacroSource(macro_loc, raw_args[1].value) + end + for arg in raw_args # For hygiene in old-style macros, we omit any additional scope # layer information from macro arguments. Old-style macros will @@ -335,7 +342,7 @@ function expand_macro(ctx, ex) # new-style macros which call old-style macros. Instead of seeing # `Expr(:escape)` in such situations, old-style macros will now see # `Expr(:scope_layer)` inside `macro_args`. - push!(macro_args, Expr(arg)) + kind(arg) !== K"VERSION" && push!(macro_args, Expr(arg)) end expanded = try Base.invoke_in_world(ctx.macro_world, macfunc, macro_args...) diff --git a/JuliaLowering/test/macros.jl b/JuliaLowering/test/macros.jl index 84c80499722f7..cd10e5f2fa445 100644 --- a/JuliaLowering/test/macros.jl +++ b/JuliaLowering/test/macros.jl @@ -122,6 +122,19 @@ ctx, expanded = JuliaLowering.expand_forms_1(test_mod, ex, false, Base.get_world "y" ] +@test JuliaLowering.include_string(test_mod, raw""" +v"1.14" +""") isa VersionNumber +@test JuliaLowering.include_string(test_mod, raw""" +v"1.14" +""";expr_compat_mode=true) isa VersionNumber +@test JuliaLowering.include_string(test_mod, raw""" +Base.Experimental.@VERSION +""") isa NamedTuple +@test JuliaLowering.include_string(test_mod, raw""" +Base.Experimental.@VERSION +""";expr_compat_mode=true) isa NamedTuple + # World age support for macro expansion JuliaLowering.include_string(test_mod, raw""" macro world_age_test()