Skip to content

Commit 6b1637b

Browse files
tkfKristofferC
authored andcommitted
Fix inference with const opaque closure (#42725)
1 parent 0848394 commit 6b1637b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

base/compiler/abstractinterpretation.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,9 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
12531253
return abstract_modifyfield!(interp, argtypes, sv)
12541254
end
12551255
return CallMeta(abstract_call_builtin(interp, f, fargs, argtypes, sv, max_methods), false)
1256+
elseif isa(f, Core.OpaqueClosure)
1257+
# calling an OpaqueClosure about which we have no information returns no information
1258+
return CallMeta(Any, false)
12561259
elseif f === Core.kwfunc
12571260
if la == 2
12581261
aty = argtypes[2]
@@ -1380,8 +1383,8 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
13801383
f = argtype_to_function(ft)
13811384
if isa(ft, PartialOpaque)
13821385
return abstract_call_opaque_closure(interp, ft, argtypes[2:end], sv)
1383-
elseif (uft = unwrap_unionall(ft); isa(uft, DataType) && uft.name === typename(Core.OpaqueClosure))
1384-
return CallMeta(rewrap_unionall((uft::DataType).parameters[2], ft), false)
1386+
elseif (uft = unwrap_unionall(widenconst(ft)); isa(uft, DataType) && uft.name === typename(Core.OpaqueClosure))
1387+
return CallMeta(rewrap_unionall((uft::DataType).parameters[2], widenconst(ft)), false)
13851388
elseif f === nothing
13861389
# non-constant function, but the number of arguments is known
13871390
# and the ft is not a Builtin or IntrinsicFunction

test/opaque_closure.jl

+5
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,8 @@ end
206206
@test f_oc_noinline_call(1, 2) == 3
207207

208208
@test_throws MethodError (@opaque x->x+1)(1, 2)
209+
210+
# https://github.com/JuliaLang/julia/issues/40409
211+
const GLOBAL_OPAQUE_CLOSURE = @opaque () -> 123
212+
call_global_opaque_closure() = GLOBAL_OPAQUE_CLOSURE()
213+
@test call_global_opaque_closure() == 123

0 commit comments

Comments
 (0)