diff --git a/src/utils.jl b/src/utils.jl index 1d1619f..784da27 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -608,7 +608,11 @@ function makeif(clauses, els = nothing) end unresolve1(x) = x -unresolve1(f::Function) = methods(f).mt.name +@static if VERSION >= v"1.12-" + unresolve1(f::Function) = nameof(f) +else + unresolve1(f::Function) = methods(f).mt.name +end unresolve(ex) = prewalk(unresolve1, ex) diff --git a/test/utils.jl b/test/utils.jl index 34621f2..f1b5765 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -63,6 +63,12 @@ end @test flatten(quote begin; begin; f(); g(); end; begin; h(); end; f(); end; end) |> striplines == quote f(); g(); h(); f() end |> striplines end +@testset "prettify" begin + # Test that prettify resolves function references to their names + @test MacroTools.prettify(:($sin(2))) == :(sin(2)) + @test MacroTools.prettify(:($cos(x))) == :(cos(x)) +end + @testset "flatten try" begin # see julia#50710 and MacroTools#194 # only tests that do not include `else` -- for the full set of tests see flatten_try.jl exs = [ quote try; f(); catch; end; end,