Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ExprTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
end # module
6 changes: 6 additions & 0 deletions src/compat.jl
Original file line number Diff line number Diff line change
@@ -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

11 changes: 8 additions & 3 deletions src/function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ 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
end
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
Expand All @@ -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
Expand Down
Loading