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

generated: Switch resolution module back to what it was before #57419

Merged
merged 1 commit into from
Feb 15, 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
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,6 @@ function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecial
Expr(:meta, :pop_loc))))
spnames = g.spnames
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),
typename(typeof(g.gen)).module,
source.module,
source.isva)
end
28 changes: 28 additions & 0 deletions test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,31 @@ end
@test first(only(code_typed((Int,Int)) do x, y; @inline overdub54341(x, y); end)) isa Core.CodeInfo
@test first(only(code_typed((Int,)) do x; @inline overdub54341(x, 1); end)) isa Core.CodeInfo
@test_throws "Wrong number of arguments" overdub54341(1, 2, 3)

# Test the module resolution scope of generated methods that are type constructors
module GeneratedScope57417
using Test
import ..generate_lambda_ex
const x = 1
struct Generator; end
@generated (::Generator)() = :x
f(x::Int) = 1
module OtherModule
import ..f
const x = 2
@generated f(::Float64) = :x
end
import .OtherModule: f
@test Generator()() == 1
@test f(1.0) == 2

function g_generator(world::UInt, source::Method, _)
return generate_lambda_ex(world, source, (:g,), (), :(return x))
end

@eval function g()
$(Expr(:meta, :generated, g_generator))
$(Expr(:meta, :generated_only))
end
@test g() == 1
end