Skip to content

Commit b2ccda1

Browse files
committed
Make no-body function declaration implicitly global
These were the intended semantics of #57311 (and matches what it used to do in 1.11). Note however that this differs from the body-ful form, which now always tries to extend. Fixes #57546.
1 parent b0323ab commit b2ccda1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/julia-syntax.scm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,9 @@
11811181
(cond ((and (length= e 2) (or (symbol? name) (globalref? name)))
11821182
(if (not (valid-name? name))
11831183
(error (string "invalid function name \"" name "\"")))
1184-
`(method ,name))
1184+
(if (globalref? name)
1185+
`(block (global ,name) (method ,name))
1186+
`(method ,name)))
11851187
((not (pair? name)) e)
11861188
((eq? (car name) 'call)
11871189
(let* ((raw-typevars (or where '()))

test/syntax.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,3 +4110,11 @@ end
41104110
# Issue #56904 - lambda linearized twice
41114111
@test (let; try 3; finally try 1; f(() -> x); catch x; end; end; x = 7; end) === 7
41124112
@test (let; try 3; finally try 4; finally try 1; f(() -> x); catch x; end; end; end; x = 7; end) === 7
4113+
4114+
# Issue #57546 - explicit function declaration should create new global
4115+
module FuncDecl57546
4116+
using Test
4117+
@test_nowarn @eval function Any end
4118+
@test isa(Any, Function)
4119+
@test isempty(methods(Any))
4120+
end

0 commit comments

Comments
 (0)