Skip to content

Commit bfaabce

Browse files
simeonschaubvtjnash
authored andcommitted
fix #44328: method validation for opaque closures (#44335)
I believe it's intentional that for these methods, the `sig` field is just ignored and always set to `Tuple`. Also fixes a lowering bug I discovered that would cause errors if `Union` was shadowed. I have verified that this fixes the reported warnings. Co-authored-by: Jameson Nash <[email protected]> (cherry picked from commit 5deb503)
1 parent 24e3c06 commit bfaabce

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

base/compiler/validation.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const NON_TOP_LEVEL_METHOD = "encountered `Expr` head `:method` in non-top-level
5353
const NON_TOP_LEVEL_GLOBAL = "encountered `Expr` head `:global` in non-top-level code (i.e. `nargs` > 0)"
5454
const SIGNATURE_NARGS_MISMATCH = "method signature does not match number of method arguments"
5555
const SLOTNAMES_NARGS_MISMATCH = "CodeInfo for method contains fewer slotnames than the number of method arguments"
56+
const INVALID_SIGNATURE_OPAQUE_CLOSURE = "invalid signature of method for opaque closure - `sig` field must always be set to `Tuple`"
5657

5758
struct InvalidCodeError <: Exception
5859
kind::String
@@ -215,7 +216,9 @@ function validate_code!(errors::Vector{>:InvalidCodeError}, mi::Core.MethodInsta
215216
m = mi.def::Method
216217
mnargs = m.nargs
217218
n_sig_params = length((unwrap_unionall(m.sig)::DataType).parameters)
218-
if (m.isva ? (n_sig_params < (mnargs - 1)) : (n_sig_params != mnargs))
219+
if m.is_for_opaque_closure
220+
m.sig === Tuple || push!(errors, InvalidCodeError(INVALID_SIGNATURE_OPAQUE_CLOSURE, (m.sig, m.isva)))
221+
elseif (m.isva ? (n_sig_params < (mnargs - 1)) : (n_sig_params != mnargs))
219222
push!(errors, InvalidCodeError(SIGNATURE_NARGS_MISMATCH, (m.isva, n_sig_params, mnargs)))
220223
end
221224
end

src/julia-syntax.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3862,7 +3862,7 @@ f(x) = yt(x)
38623862
v)))
38633863
cvs)))
38643864
`(new_opaque_closure
3865-
,(cadr e) (call (core apply_type) Union) (core Any)
3865+
,(cadr e) (call (core apply_type) (core Union)) (core Any)
38663866
(opaque_closure_method (null) ,nargs ,isva ,functionloc ,(convert-lambda lam2 (car (lam:args lam2)) #f '() (symbol-to-idx-map cvs)))
38673867
,@var-exprs))))
38683868
((method)

0 commit comments

Comments
 (0)