@@ -3804,7 +3804,7 @@ module ImplicitCurlies
38043804 end
38053805 @test ! @isdefined (ImplicitCurly6)
38063806 # Check return value of assignment expr
3807- @test isa (( const ImplicitCurly7{T} = Ref{T}), UnionAll)
3807+ @test isa (Core . eval ( @__MODULE__ , :( const ImplicitCurly7{T} = Ref{T}) ), UnionAll)
38083808 @test isa (begin ; ImplicitCurly8{T} = Ref{T}; end , UnionAll)
38093809end
38103810
@@ -3840,7 +3840,8 @@ const (gconst_assign(), hconst_assign()) = (2, 3)
38403840# and the conversion, but not the rhs.
38413841struct CantConvert; end
38423842Base. convert (:: Type{CantConvert} , x) = error ()
3843- @test (const _:: CantConvert = 1 ) == 1
3843+ # @test splices into a function, where const cannot appear
3844+ @test Core. eval (@__MODULE__ , :(const _:: CantConvert = 1 )) == 1
38443845@test ! isconst (@__MODULE__ , :_ )
38453846@test_throws ErrorException (" expected" ) (const _ = error (" expected" ))
38463847
@@ -4110,3 +4111,70 @@ end
41104111# Issue #56904 - lambda linearized twice
41114112@test (let ; try 3 ; finally try 1 ; f (() -> x); catch x; end ; end ; x = 7 ; end ) === 7
41124113@test (let ; try 3 ; finally try 4 ; finally try 1 ; f (() -> x); catch x; end ; end ; end ; x = 7 ; end ) === 7
4114+
4115+ # #57334
4116+ let
4117+ x57334 = Ref (1 )
4118+ @test_throws " syntax: cannot declare \" x57334[]\" `const`" Core. eval (@__MODULE__ , :(const x57334[] = 1 ))
4119+ end
4120+
4121+ # #57470
4122+ module M57470
4123+ using .. Test
4124+
4125+ @test_throws (
4126+ " syntax: `global const` declaration not allowed inside function" ,
4127+ Core. eval (@__MODULE__ , :(function f57470 ()
4128+ const global x57470 = 1
4129+ end )))
4130+ @test_throws (
4131+ " unsupported `const` declaration on local variable" ,
4132+ Core. eval (@__MODULE__ , :(let
4133+ const y57470 = 1
4134+ end ))
4135+ )
4136+
4137+ let
4138+ global a57470
4139+ const a57470 = 1
4140+ end
4141+ @test a57470 === 1
4142+
4143+ let
4144+ global const z57470 = 1
4145+ const global w57470 = 1
4146+ end
4147+
4148+ @test z57470 === 1
4149+ @test w57470 === 1
4150+
4151+ const (; field57470_1, field57470_2) = (field57470_1 = 1 , field57470_2 = 2 )
4152+ @test field57470_1 === 1
4153+ @test field57470_2 === 2
4154+
4155+ # TODO : 1.11 allows these, but should we?
4156+ const X57470{T}, Y57470{T} = Int, Bool
4157+ @test X57470 === Int
4158+ @test Y57470 === Bool
4159+ const A57470{T}, B57470{T} = [Int, Bool]
4160+ @test A57470 === Int
4161+ @test B57470 === Bool
4162+ const a57470, f57470 (x), T57470{U} = [1 , 2 , Int]
4163+ @test a57470 === 1
4164+ @test f57470 (0 ) === 2
4165+ @test T57470 === Int
4166+
4167+ module M57470_sub end
4168+ @test_throws (" syntax: cannot declare \" M57470_sub.x\" `const`" ,
4169+ Core. eval (@__MODULE__ , :(const M57470_sub. x = 1 )))
4170+
4171+ # # `const global` should not trample previously declared `local`
4172+ @test_throws (
4173+ " syntax: variable \" v57470\" declared both local and global" ,
4174+ Core. eval (@__MODULE__ , :(let
4175+ local v57470
4176+ const global v57470 = 1
4177+ end ))
4178+ )
4179+
4180+ end
0 commit comments