Skip to content

Commit 0c5372f

Browse files
authored
generated: Switch resolution module back to what it was before (#57419)
This addresses post-commit review #57230 (comment). This change was left-over from before I decided to also change the type of the `source` argument (at which point `source.module` was unavailable in the function). This module was supposed to be the same, but it turns out that both the julia tests and several packages use this code manually and use different modules for the two places. Use the same one we used before (which is probably more correct anyway) to fix #57417
1 parent 2364719 commit 0c5372f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,6 @@ function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecial
16941694
Expr(:meta, :pop_loc))))
16951695
spnames = g.spnames
16961696
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),
1697-
typename(typeof(g.gen)).module,
1697+
source.module,
16981698
source.isva)
16991699
end

test/staged.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,31 @@ end
449449
@test first(only(code_typed((Int,Int)) do x, y; @inline overdub54341(x, y); end)) isa Core.CodeInfo
450450
@test first(only(code_typed((Int,)) do x; @inline overdub54341(x, 1); end)) isa Core.CodeInfo
451451
@test_throws "Wrong number of arguments" overdub54341(1, 2, 3)
452+
453+
# Test the module resolution scope of generated methods that are type constructors
454+
module GeneratedScope57417
455+
using Test
456+
import ..generate_lambda_ex
457+
const x = 1
458+
struct Generator; end
459+
@generated (::Generator)() = :x
460+
f(x::Int) = 1
461+
module OtherModule
462+
import ..f
463+
const x = 2
464+
@generated f(::Float64) = :x
465+
end
466+
import .OtherModule: f
467+
@test Generator()() == 1
468+
@test f(1.0) == 2
469+
470+
function g_generator(world::UInt, source::Method, _)
471+
return generate_lambda_ex(world, source, (:g,), (), :(return x))
472+
end
473+
474+
@eval function g()
475+
$(Expr(:meta, :generated, g_generator))
476+
$(Expr(:meta, :generated_only))
477+
end
478+
@test g() == 1
479+
end

0 commit comments

Comments
 (0)