Skip to content

Commit ca17927

Browse files
authored
lowering: Don't closure-convert in import or using (#57774)
Fixes #57702. We're calling cl-convert- on `using` and `import` statements when we shouldn't, so if there's a nearby local that gets boxed (recursive function definition in this case), and the local shares a name with something in an import statement, we get a box access where we want a raw symbol. Before: ``` julia> let; let; import SHA: R; end; let; R(x...) = R(x); end; end ERROR: TypeError: in import, expected Symbol, got a value of type Expr Stacktrace: [1] top-level scope @ REPL[1]:1 ``` After: ``` julia> let; let; import SHA: R; end; let; R(x...) = R(x); end; end (::var"#R#R##0") (generic function with 1 method) ``` Previously, symbols in `import`/`using` statements would be wrapped with `outerref`, which cl-convert- wouldn't peek into. This protected us from this problem in 1.11.
1 parent 22805e6 commit ca17927

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/julia-syntax.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4003,7 +4003,7 @@ f(x) = yt(x)
40034003
((atom? e) e)
40044004
(else
40054005
(case (car e)
4006-
((quote top core globalref thismodule lineinfo line break inert module toplevel null true false meta) e)
4006+
((quote top core globalref thismodule lineinfo line break inert module toplevel null true false meta import using) e)
40074007
((toplevel-only)
40084008
;; hack to avoid generating a (method x) expr for struct types
40094009
(if (eq? (cadr e) 'struct)

test/syntax.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,18 @@ import .TestImportAs.Mod2 as M2
26932693
@test !@isdefined(Mod2)
26942694
@test M2 === TestImportAs.Mod2
26952695

2696+
# 57702: nearby bindings shouldn't cause us to closure-convert in import/using
2697+
module OddImports
2698+
using Test
2699+
module ABC end
2700+
x = let; let; import .ABC; end; let; ABC() = (ABC,); end; end
2701+
y = let; let; using .ABC; end; let; ABC() = (ABC,); end; end
2702+
z = let; let; import SHA: R; end; let; R(x...) = R(x); end; end
2703+
@test x isa Function
2704+
@test y isa Function
2705+
@test z isa Function
2706+
end
2707+
26962708
@testset "unicode modifiers after '" begin
26972709
@test Meta.parse("a'ᵀ") == Expr(:call, Symbol("'ᵀ"), :a)
26982710
@test Meta.parse("a'⁻¹") == Expr(:call, Symbol("'⁻¹"), :a)

0 commit comments

Comments
 (0)