Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix opaque_closure sparam capture #57928

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4109,6 +4109,7 @@ f(x) = yt(x)
(capt-var-access v fname opaq)
v)))
cvs)))
(set-car! (cdddr (lam:vinfo lam2)) '()) ;; must capture static_parameters as values inside opaque_closure
`(new_opaque_closure
,(cadr e) ,(or (caddr e) '(call (core apply_type) (core Union))) ,(or (cadddr e) '(core Any)) ,allow-partial
(opaque_closure_method (null) ,nargs ,isva ,functionloc ,(convert-lambda lam2 (car (lam:args lam2)) #f '() (symbol-to-idx-map cvs) parsed-method-stack))
Expand Down
17 changes: 17 additions & 0 deletions test/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,20 @@ let ir = first(only(Base.code_ircode(sin, (Int,))))
oc = Core.OpaqueClosure(ir; do_compile=false)
@test oc(1) == sin(1)
end

function typed_add54236(::Type{T}) where T
return @opaque (x::Int)->T(x) + T(1)
end
let f = typed_add54236(Float64)
@test f isa Core.OpaqueClosure
@test f(32) === 33.0
end

f54357(g, ::Type{AT}) where {AT} = Base.Experimental.@opaque AT->_ (args...) -> g((args::AT)...)
let f = f54357(+, Tuple{Int,Int})
@test f isa Core.OpaqueClosure
@test f(32, 34) === 66
g = f54357(+, Tuple{Float64,Float64})
@test g isa Core.OpaqueClosure
@test g(32.0, 34.0) === 66.0
end