Skip to content

Commit 4e645f5

Browse files
committed
Add tests for #57334, #57470
Also update some tests that used @test with a quote containing `const`, which cannot be spliced into a function.
1 parent b9a8d46 commit 4e645f5

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

test/syntax.jl

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,7 +3800,7 @@ module ImplicitCurlies
38003800
end
38013801
@test !@isdefined(ImplicitCurly6)
38023802
# Check return value of assignment expr
3803-
@test isa((const ImplicitCurly7{T} = Ref{T}), UnionAll)
3803+
@test isa(Core.eval(@__MODULE__, :(const ImplicitCurly7{T} = Ref{T})), UnionAll)
38043804
@test isa(begin; ImplicitCurly8{T} = Ref{T}; end, UnionAll)
38053805
end
38063806

@@ -3836,7 +3836,8 @@ const (gconst_assign(), hconst_assign()) = (2, 3)
38363836
# and the conversion, but not the rhs.
38373837
struct CantConvert; end
38383838
Base.convert(::Type{CantConvert}, x) = error()
3839-
@test (const _::CantConvert = 1) == 1
3839+
# @test splices into a function, where const cannot appear
3840+
@test Core.eval(@__MODULE__, :(const _::CantConvert = 1)) == 1
38403841
@test !isconst(@__MODULE__, :_)
38413842
@test_throws ErrorException("expected") (const _ = error("expected"))
38423843

@@ -4102,3 +4103,70 @@ module Ambig57404
41024103
using .B
41034104
end
41044105
@test Ambig57404.S == 1
4106+
4107+
# #57334
4108+
let
4109+
x57334 = Ref(1)
4110+
@test_throws "syntax: cannot declare \"x57334[]\" `const`" Core.eval(@__MODULE__, :(const x57334[] = 1))
4111+
end
4112+
4113+
# #57470
4114+
module M57470
4115+
using ..Test
4116+
4117+
@test_throws(
4118+
"syntax: `global const` declaration not allowed inside function",
4119+
Core.eval(@__MODULE__, :(function f57470()
4120+
const global x57470 = 1
4121+
end)))
4122+
@test_throws(
4123+
"unsupported `const` declaration on local variable",
4124+
Core.eval(@__MODULE__, :(let
4125+
const y57470 = 1
4126+
end))
4127+
)
4128+
4129+
let
4130+
global a57470
4131+
const a57470 = 1
4132+
end
4133+
@test a57470 === 1
4134+
4135+
let
4136+
global const z57470 = 1
4137+
const global w57470 = 1
4138+
end
4139+
4140+
@test z57470 === 1
4141+
@test w57470 === 1
4142+
4143+
const (; field57470_1, field57470_2) = (field57470_1 = 1, field57470_2 = 2)
4144+
@test field57470_1 === 1
4145+
@test field57470_2 === 2
4146+
4147+
# TODO: 1.11 allows these, but should we?
4148+
const X57470{T}, Y57470{T} = Int, Bool
4149+
@test X57470 === Int
4150+
@test Y57470 === Bool
4151+
const A57470{T}, B57470{T} = [Int, Bool]
4152+
@test A57470 === Int
4153+
@test B57470 === Bool
4154+
const a57470, f57470(x), T57470{U} = [1, 2, Int]
4155+
@test a57470 === 1
4156+
@test f57470(0) === 2
4157+
@test T57470 === Int
4158+
4159+
module M57470_sub end
4160+
@test_throws("syntax: cannot declare \"M57470_sub.x\" `const`",
4161+
Core.eval(@__MODULE__, :(const M57470_sub.x = 1)))
4162+
4163+
# # `const global` should not trample previously declared `local`
4164+
@test_throws(
4165+
"syntax: variable \"v57470\" declared both local and global",
4166+
Core.eval(@__MODULE__, :(let
4167+
local v57470
4168+
const global v57470 = 1
4169+
end))
4170+
)
4171+
4172+
end

0 commit comments

Comments
 (0)