|
16 | 16 | function matching_cache_argtypes(linfo::MethodInstance, given_argtypes::Vector, va_override::Bool) |
17 | 17 | @assert isa(linfo.def, Method) # ensure the next line works |
18 | 18 | nargs::Int = linfo.def.nargs |
19 | | - @assert length(given_argtypes) >= (nargs - 1) |
20 | 19 | given_argtypes = anymap(widenconditional, given_argtypes) |
21 | | - if va_override || linfo.def.isva |
| 20 | + isva = va_override || linfo.def.isva |
| 21 | + if isva || isvarargtype(given_argtypes[end]) |
22 | 22 | isva_given_argtypes = Vector{Any}(undef, nargs) |
23 | | - for i = 1:(nargs - 1) |
| 23 | + for i = 1:(nargs - isva) |
24 | 24 | isva_given_argtypes[i] = argtype_by_index(given_argtypes, i) |
25 | 25 | end |
26 | | - if length(given_argtypes) >= nargs || !isvarargtype(given_argtypes[end]) |
27 | | - isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[nargs:end]) |
28 | | - else |
29 | | - isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[end:end]) |
| 26 | + if isva |
| 27 | + if length(given_argtypes) < nargs && isvarargtype(given_argtypes[end]) |
| 28 | + last = length(given_argtypes) |
| 29 | + else |
| 30 | + last = nargs |
| 31 | + end |
| 32 | + isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[last:end]) |
30 | 33 | end |
31 | 34 | given_argtypes = isva_given_argtypes |
32 | 35 | end |
| 36 | + @assert length(given_argtypes) == nargs |
33 | 37 | cache_argtypes, overridden_by_const = matching_cache_argtypes(linfo, nothing, va_override) |
34 | | - if nargs === length(given_argtypes) |
35 | | - for i in 1:nargs |
36 | | - given_argtype = given_argtypes[i] |
37 | | - cache_argtype = cache_argtypes[i] |
38 | | - if !is_argtype_match(given_argtype, cache_argtype, overridden_by_const[i]) |
39 | | - # prefer the argtype we were given over the one computed from `linfo` |
40 | | - cache_argtypes[i] = given_argtype |
41 | | - overridden_by_const[i] = true |
42 | | - end |
| 38 | + for i in 1:nargs |
| 39 | + given_argtype = given_argtypes[i] |
| 40 | + cache_argtype = cache_argtypes[i] |
| 41 | + if !is_argtype_match(given_argtype, cache_argtype, overridden_by_const[i]) |
| 42 | + # prefer the argtype we were given over the one computed from `linfo` |
| 43 | + cache_argtypes[i] = given_argtype |
| 44 | + overridden_by_const[i] = true |
43 | 45 | end |
44 | 46 | end |
45 | 47 | return cache_argtypes, overridden_by_const |
|
0 commit comments