Skip to content

Commit 696d9c3

Browse files
authored
Follow up #54772 - don't accidentally put Module into method name slot (#54856)
The `:outerref` removal (#54772) ended up accidentally putting a `Module` argument into 3-argument `:method` due to a bad refactor. We didn't catch this in the tests, because the name slot of 3-argument `:method` is unused (except for external method tables), but ordinarily contains the same data as 1-argument `:method`. That said, some packages in the Revise universe look at this (arguably incorrectly, since they should be looking at the signature instead), so it should be correct until we fix Revise, at which point we may just want to always pass `false` here.
1 parent dfd1d49 commit 696d9c3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/julia-syntax.scm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,8 @@
227227

228228
(define (method-expr-name m)
229229
(let ((name (cadr m)))
230-
(let ((name (if (or (length= m 2) (not (pair? name)) (not (quoted? name))) name (cadr name))))
231-
(cond ((not (pair? name)) name)
232-
((eq? (car name) 'globalref) (caddr name))
233-
(else name)))))
230+
(cond ((globalref? name) (caddr name))
231+
(else name))))
234232

235233
;; extract static parameter names from a (method ...) expression
236234
(define (method-expr-static-parameters m)
@@ -4087,7 +4085,7 @@ f(x) = yt(x)
40874085
(newlam (compact-and-renumber (linearize (car exprs)) 'none 0)))
40884086
`(toplevel-butfirst
40894087
(block ,@sp-inits
4090-
(method ,name ,(cl-convert sig fname lam namemap defined toplevel interp opaq globals locals)
4088+
(method ,(cadr e) ,(cl-convert sig fname lam namemap defined toplevel interp opaq globals locals)
40914089
,(julia-bq-macro newlam)))
40924090
,@top-stmts))))
40934091

test/syntax.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,3 +3845,16 @@ struct SingletonMaker; end
38453845
const no_really_this_is_a_function_i_promise = Val{SingletonMaker()}()
38463846
no_really_this_is_a_function_i_promise(a) = 2 + a
38473847
@test Val{SingletonMaker()}()(2) == 4
3848+
3849+
# Test that lowering doesn't accidentally put a `Module` in the Method name slot
3850+
let src = @Meta.lower let capture=1
3851+
global foo_lower_block
3852+
foo_lower_block() = capture
3853+
end
3854+
code = src.args[1].code
3855+
for i = length(code):-1:1
3856+
expr = code[i]
3857+
Meta.isexpr(expr, :method) || continue
3858+
@test isa(expr.args[1], Union{GlobalRef, Symbol})
3859+
end
3860+
end

0 commit comments

Comments
 (0)