Skip to content

Commit bf0a1ef

Browse files
authored
Also handle splats in interpolated args (#111)
If an arg is interpolated and has a splat, we can't be sure that arguments will be aligned anymore. Terminate the validation. Improves #110 and the fix for JuliaDebug/Cthulhu.jl#425
1 parent 1a1d7ab commit bf0a1ef

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/utils.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ function is_func_expr(@nospecialize(ex), meth::Method)
118118
margs = margs[idx:end]
119119
end
120120
for (arg, marg) in zip(exargs, margs[2:end])
121-
isexpr(arg, :$) && continue
121+
if isexpr(arg, :$)
122+
# If this is a splat, we may not even have the right number of args. In that case,
123+
# just trust the matching we've done so far.
124+
lastarg = arg.args[end]
125+
isexpr(lastarg, :...) && return true
126+
continue
127+
end
122128
aname = get_argname(arg)
123129
aname === :_ && continue
124130
aname === marg || (aname === Symbol("#unused#") && marg === Symbol("")) || return false

test/runtests.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,40 +206,45 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
206206
src, line = definition(String, m)
207207
@test occursin("atan(y, x)", src)
208208
@test line == 93
209+
m = which(hasthreeargs, (Real, Real, Bool))
210+
src, line = definition(String, m)
211+
@test occursin("x + y + z", src)
212+
@test line == 94
213+
209214

210215
# unnamed arguments
211216
m = which(unnamedarg, (Type{String}, Any))
212217
src, line = definition(String, m)
213218
@test occursin("string(x)", src)
214-
@test line == 98
219+
@test line == 97
215220
m = which(mypush!, (Nowhere, Any))
216221
src, line = definition(String, m)
217222
@test occursin("::Nowhere", src)
218-
@test line == 113
223+
@test line == 112
219224

220225
# global annotations
221226
m = which(inlet, (Any,))
222227
src, line = definition(String, m)
223228
@test occursin("inlet(x)", src)
224-
@test line == 117
229+
@test line == 116
225230

226231
# Callables
227232
gg = Gaussian(1.0)
228233
m = @which gg(2)
229234
src, line = definition(String, m)
230235
@test occursin("::Gaussian)(x)", src)
231-
@test line == 124
236+
@test line == 123
232237
invt = Invert()
233238
m = @which invt([false, true])
234239
src, line = definition(String, m)
235240
@test occursin("::Invert)(v", src)
236-
@test line == 126
241+
@test line == 125
237242

238243
# Constructor with `where`
239244
m = @which Invert((false, true))
240245
src, line = definition(String, m)
241246
@test occursin("(::Type{T})(itr) where {T<:Invert}", src)
242-
@test line == 127
247+
@test line == 126
243248

244249
# Invalidation-insulating methods used by Revise and perhaps others
245250
d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}()

test/script.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ for f in (:mysin,)
9090
end
9191
mysin(x::AbstractFloat) = sin(x)
9292
let args = [:(y::Real), :(x::Real)]
93-
@eval function dollaratan($(args...))
94-
return atan(y, x)
95-
end
93+
@eval dollaratan($(args...)) = atan(y, x)
94+
@eval hasthreeargs($(args...), z::Bool) = x + y + z
9695
end
9796

9897
unnamedarg(::Type{String}, x) = string(x) # see more unnamed on line 108

0 commit comments

Comments
 (0)