diff --git a/src/ExprTools.jl b/src/ExprTools.jl index 1a7ded6..4bfb43c 100644 --- a/src/ExprTools.jl +++ b/src/ExprTools.jl @@ -2,9 +2,10 @@ module ExprTools export args_tuple_expr, combinedef, parameters, signature, splitdef +include("compat.jl") include("function.jl") include("method.jl") include("type_utils.jl") include("def_tools.jl") -end # module \ No newline at end of file +end # module diff --git a/src/compat.jl b/src/compat.jl new file mode 100644 index 0000000..9ef9d83 --- /dev/null +++ b/src/compat.jl @@ -0,0 +1,6 @@ +@static if !isdefined(Base, :LazyString) + # `LazyString` was added in Julia 1.8. On older versions fall back to eagerly + # building the string; correctness is preserved, only the laziness is lost. + LazyString(parts...) = string(parts...) +end + diff --git a/src/function.jl b/src/function.jl index 17a9b93..ce50eff 100644 --- a/src/function.jl +++ b/src/function.jl @@ -26,7 +26,10 @@ function splitdef(ex::Expr; throw::Bool=true) function invalid_def(section) if throw - msg = "Function definition contains $section\n$(sprint(Meta.dump, full_ex))" + msg = LazyString( + "Function definition contains ", section, "\n", + sprint(Meta.dump, full_ex), + ) Base.throw(ArgumentError(msg)) else nothing @@ -34,7 +37,7 @@ function splitdef(ex::Expr; throw::Bool=true) end if !(ex.head === :function || ex.head === :(=) || ex.head === :(->)) - return invalid_def("invalid function head `$(repr(ex.head))`") + return invalid_def(LazyString("invalid function head `", ex.head, "`")) end def[:head] = ex.head @@ -48,7 +51,9 @@ function splitdef(ex::Expr; throw::Bool=true) ex = ex.args[1] # Focus on the function signature else quan = length(ex.args) > 2 ? "too many" : "too few" - return invalid_def("$quan of expression arguments for `$(repr(def[:head]))`") + return invalid_def( + LazyString(quan, " of expression arguments for `", def[:head], "`"), + ) end # Where parameters