Skip to content

Commit fdacea5

Browse files
authored
Merge pull request #162 from aviatesk/juliacon
improve code quality and type instabilities
2 parents fef1c6f + 466d616 commit fdacea5

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

src/match/match.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ isbinding(s) = false
2424
isbinding(s::Symbol) = occursin(r"[^_]_(_str)?$", string(s))
2525

2626
function bname(s::Symbol)
27-
Symbol(Base.match(r"^@?(.*?)_+(_str)?$", string(s)).captures[1])
27+
Symbol(something(Base.match(r"^@?(.*?)_+(_str)?$", string(s))).captures[1])
2828
end
2929

3030
function match_inner(pat, ex, env)

src/match/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function tbnew(s::Symbol)
1717
istb(s) || return s
1818
ts = map(Symbol, split(string(s), "_"))
1919
name = popfirst!(ts)
20-
ts = map(totype, ts)
20+
ts = (totype(t) for t in ts)
2121
Expr(:$, :(MacroTools.TypeBind($(Expr(:quote, name)), Set{Any}([$(ts...)]))))
2222
end
2323

src/structdef.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function splitstructdef(ex)
1212
else
1313
parse_error(ex)
1414
end
15-
15+
1616
if @capture header nameparam_ <: super_
1717
nothing
1818
elseif @capture header nameparam_
@@ -44,6 +44,8 @@ function splitstructdef(ex)
4444
d
4545
end
4646

47+
parse_error(ex) = throw(ArgumentError("failed to split $(repr(ex))"))
48+
4749
function combinestructdef(d)::Expr
4850
name = d[:name]
4951
parameters = d[:params]

src/utils.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,6 @@ function combinearg(arg_name, arg_type, is_splat, default)
417417
return default === nothing ? a2 : Expr(:kw, a2, default)
418418
end
419419

420-
421-
macro splitcombine(fundef)
422-
dict = splitdef(fundef)
423-
esc(rebuilddef(striplines(dict)))
424-
end
425-
426-
427420
"""
428421
splitarg(arg)
429422
@@ -444,11 +437,11 @@ See also: [`combinearg`](@ref)
444437
"""
445438
function splitarg(arg_expr)
446439
splitvar(arg) =
447-
@match arg begin
440+
(@match arg begin
448441
::T_ => (nothing, T)
449442
name_::T_ => (name, T)
450443
x_ => (x, :Any)
451-
end
444+
end)::NTuple{2,Any} # the pattern `x_` matches any expression
452445
(is_splat = @capture(arg_expr, arg_expr2_...)) || (arg_expr2 = arg_expr)
453446
if @capture(arg_expr2, arg_ = default_)
454447
@assert default !== nothing "splitarg cannot handle `nothing` as a default. Use a quoted `nothing` if possible. (MacroTools#35)"

test/split.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ end
112112
@test first(constructors) ==
113113
:((S(a::A) where A) = new{A}()) |> MacroTools.flatten
114114

115+
@test_throws ArgumentError splitstructdef(:(call_ex(arg)))
115116
end

0 commit comments

Comments
 (0)