Skip to content

Commit ca737d3

Browse files
committed
Tweak diagnostic text on @section/@const errors
1 parent f41ce33 commit ca737d3

File tree

9 files changed

+61
-61
lines changed

9 files changed

+61
-61
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -826,29 +826,29 @@ ERROR(expect_compile_time_literal,none,
826826
"expect a compile-time constant literal", ())
827827

828828
ERROR(const_unsupported_enum_associated_value,none,
829-
"enums with associated values not supported in a '@const' expression", ())
829+
"enums with associated values not supported in a constant expression", ())
830830
ERROR(const_unsupported_operator,none,
831-
"unsupported operator in a '@const' expression", ())
831+
"unsupported operator in a constant expression", ())
832832
ERROR(const_unsupported_type,none,
833-
"unsupported type in a '@const' expression", ())
833+
"unsupported type in a constant expression", ())
834834
ERROR(const_unsupported_type_expr,none,
835-
"type expressions not supported in a '@const' expression", ())
835+
"type expressions not supported in a constant expression", ())
836836
ERROR(const_unsupported_closure,none,
837-
"closures not supported in a '@const' expression", ())
837+
"closures not supported in a constant expression", ())
838838
ERROR(const_unsupported_keypath,none,
839-
"keypaths not supported in a '@const' expression", ())
839+
"keypaths not supported in a constant expression", ())
840840
ERROR(const_opaque_decl_ref,none,
841-
"unable to resolve variable reference in a '@const' expression", ())
841+
"unable to resolve variable reference in a constant expression", ())
842842
ERROR(const_opaque_func_decl_ref,none,
843-
"unable to resolve function reference in a '@const' expression", ())
843+
"unable to resolve function reference in a constant expression", ())
844844
ERROR(const_non_convention_c_conversion,none,
845-
"only 'convention(c)' function values are supported in a '@const' expression", ())
845+
"only 'convention(c)' function values are supported in a constant expression", ())
846846
ERROR(const_opaque_callee,none,
847-
"unable to resolve callee in a '@const' expression", ())
847+
"unable to resolve callee in a constant expression", ())
848848
ERROR(const_non_const_param,none,
849-
"reference to a non-'@const' parameter in a '@const' expression", ())
849+
"reference to a non-'@const' parameter in a constant expression", ())
850850
ERROR(const_unknown_default,none,
851-
"not supported in a '@const' expression", ())
851+
"not supported in a constant expression", ())
852852

853853
//------------------------------------------------------------------------------
854854
// MARK: Import Resolution

test/ConstValues/DiagModulesSyntactic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ public func foo() -> Int {
1717
import MyModule
1818

1919
@const let constGlobal1: Int = foo()
20-
// expected-error@-1 {{not supported in a '@const' expression}}
20+
// expected-error@-1 {{not supported in a constant expression}}

test/ConstValues/DiagNotConstSyntactic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// RUN: %target-swift-frontend -emit-ir -primary-file %s -parse-as-library -verify -enable-experimental-feature CompileTimeValues
44

55
@const let a: Bool = Bool.random()
6-
// expected-error@-1 {{not supported in a '@const' expression}}
6+
// expected-error@-1 {{not supported in a constant expression}}
77

88
func foo() -> Int {
99
return 42 * Int.random(in: 0 ..< 10)
1010
}
1111

1212
@const let b: Int = foo()
13-
// expected-error@-1 {{not supported in a '@const' expression}}
13+
// expected-error@-1 {{not supported in a constant expression}}

test/ConstValues/FunctionTypesSyntactic.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ func foo_void_to_void() {}
66
func foo_int_to_int(x: Int) -> Int { return 42 }
77

88
@const let constGlobalA1: ()->() = { }
9-
// expected-error@-1{{closures not supported in a '@const' expression}}
9+
// expected-error@-1{{closures not supported in a constant expression}}
1010
@const let constGlobalA2: @convention(c) ()->() = { }
11-
// expected-error@-1{{closures not supported in a '@const' expression}}
11+
// expected-error@-1{{closures not supported in a constant expression}}
1212
@const let constGlobalA3: @convention(thin) ()->() = { }
13-
// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}}
13+
// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}}
1414

1515
@const let constGlobalB1: ()->() = foo_void_to_void // TODO: Diagnose the type of the variable as not eligigle for '@const' (not the init expression)
1616
@const let constGlobalB2: @convention(c) ()->() = foo_void_to_void
1717
@const let constGlobalB3: @convention(thin) ()->() = foo_void_to_void
18-
// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}}
18+
// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}}
1919

2020
@const let constGlobalC1: (Int)->(Int) = { _ in return 42 }
21-
// expected-error@-1{{closures not supported in a '@const' expression}}
21+
// expected-error@-1{{closures not supported in a constant expression}}
2222
@const let constGlobalC2: @convention(c) (Int)->(Int) = { _ in return 42 }
23-
// expected-error@-1{{closures not supported in a '@const' expression}}
23+
// expected-error@-1{{closures not supported in a constant expression}}
2424
@const let constGlobalC3: @convention(thin) (Int)->(Int) = { _ in return 42 }
25-
// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}}
25+
// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}}
2626

2727
@const let constGlobalD1: (Int)->(Int) = foo_int_to_int
2828
@const let constGlobalD2: @convention(c) (Int)->(Int) = foo_int_to_int
2929
@const let constGlobalD3: @convention(thin) (Int)->(Int) = foo_int_to_int
30-
// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}}
30+
// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}}

test/ConstValues/IntegerExpressionsSyntactic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
@const let constGlobal1: Int = (42 + 42 + 42) / 3
77
@const let constGlobal2: Int = MemoryLayout<UInt32>.size + 4
8-
// expected-error@-1{{in a '@const' expression}}
8+
// expected-error@-1{{in a constant expression}}
99
@const let constGlobal3: Int = Int(17.0 / 3.5)
1010
@const let constGlobal4: Int = constGlobal1 + 1
1111
@const let constGlobal5: Int = -constGlobal1 + 1

test/ConstValues/ParametersSyntactic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ func foo() {
1414
#endif
1515
let _ = bar(UInt.random(in: 0..<10))
1616
// expected-error@-1 {{expected a compile-time value argument for a '@const' parameter}}
17-
// expected-error@-2 {{not supported in a '@const' expression}}
17+
// expected-error@-2 {{not supported in a constant expression}}
1818
}

test/ConstValues/SectionSyntactic.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626

2727
// operators (should be rejected)
2828
@section("mysection") let invalidOperator1 = 1 + 1
29-
// expected-error@-1{{unsupported operator in a '@const' expression}}
29+
// expected-error@-1{{unsupported operator in a constant expression}}
3030
@section("mysection") let invalidOperator2 = 3.14 * 2.0
31-
// expected-error@-1{{unsupported operator in a '@const' expression}}
31+
// expected-error@-1{{unsupported operator in a constant expression}}
3232
@section("mysection") let invalidOperator3: Int = -(1)
33-
// expected-error@-1{{unsupported operator in a '@const' expression}}
33+
// expected-error@-1{{unsupported operator in a constant expression}}
3434

3535
// non-literal expressions (should be rejected)
3636
@section("mysection") let invalidNonLiteral1 = Int.max
37-
// expected-error@-1{{not supported in a '@const' expression}}
37+
// expected-error@-1{{not supported in a constant expression}}
3838
@section("mysection") let invalidNonLiteral2 = UInt8(42)
39-
// expected-error@-1{{not supported in a '@const' expression}}
39+
// expected-error@-1{{not supported in a constant expression}}
4040
@section("mysection") let invalidNonLiteral3 = true.hashValue
41-
// expected-error@-1{{not supported in a '@const' expression}}
41+
// expected-error@-1{{not supported in a constant expression}}
4242

4343
func foo() -> Int { return 42 }
4444
func bar(x: Int) -> String { return "test" }
@@ -49,21 +49,21 @@ func bar(x: Int) -> String { return "test" }
4949

5050
// invalid function references (should be rejected)
5151
@section("mysection") let invalidFuncRef1 = foo()
52-
// expected-error@-1{{not supported in a '@const' expression}}
52+
// expected-error@-1{{not supported in a constant expression}}
5353
@section("mysection") let invalidFuncRef2 = Bool.self.random
54-
// expected-error@-1{{closures not supported in a '@const' expression}}
54+
// expected-error@-1{{closures not supported in a constant expression}}
5555
@section("mysection") let invalidFuncRef3 = (Bool.self as Bool.Type).random
56-
// expected-error@-1{{not supported in a '@const' expression}}
56+
// expected-error@-1{{not supported in a constant expression}}
5757

5858
// generic function references (should be rejected)
5959
@section("mysection") let invalidGenericFunc = [Int].randomElement
60-
// expected-error@-1{{not supported in a '@const' expression}}
60+
// expected-error@-1{{not supported in a constant expression}}
6161

6262
// closures (should be rejected)
6363
@section("mysection") let invalidClosure1 = { }
64-
// expected-error@-1{{closures not supported in a '@const' expression}}
64+
// expected-error@-1{{closures not supported in a constant expression}}
6565
@section("mysection") let invalidClosure2 = { return 42 }
66-
// expected-error@-1{{closures not supported in a '@const' expression}}
66+
// expected-error@-1{{closures not supported in a constant expression}}
6767

6868
struct S { }
6969
enum E { case a }
@@ -73,13 +73,13 @@ enum E { case a }
7373

7474
// invalid metatype references
7575
@section("mysection") let invalidMetatype1 = Int.self.self
76-
// expected-error@-1{{type expressions not supported in a '@const' expression}}
76+
// expected-error@-1{{type expressions not supported in a constant expression}}
7777
@section("mysection") let invalidMetatype2 = (1 == 1 ? Int.self : Int.self).self
78-
// expected-error@-1{{type expressions not supported in a '@const' expression}}
78+
// expected-error@-1{{type expressions not supported in a constant expression}}
7979
@section("mysection") let invalidMetatype3 = Array<Int>.self // generic
80-
// expected-error@-1{{type expressions not supported in a '@const' expression}}
80+
// expected-error@-1{{type expressions not supported in a constant expression}}
8181
@section("mysection") let invalidMetatype4 = Mirror.self // resilient
82-
// expected-error@-1{{type expressions not supported in a '@const' expression}}
82+
// expected-error@-1{{type expressions not supported in a constant expression}}
8383

8484
// tuples
8585
@section("mysection") let tuple1 = (1, 2, 3, 2.718, true) // ok
@@ -88,35 +88,35 @@ enum E { case a }
8888

8989
// invalid tuples (should be rejected)
9090
@section("mysection") let invalidTuple1 = (1, 2, Int.max)
91-
// expected-error@-1{{not supported in a '@const' expression}}
91+
// expected-error@-1{{not supported in a constant expression}}
9292
@section("mysection") let invalidTuple2 = (1 + 1, 2)
93-
// expected-error@-1{{unsupported operator in a '@const' expression}}
93+
// expected-error@-1{{unsupported operator in a constant expression}}
9494

9595
let someVar = 42
9696

9797
// variables (should be rejected)
9898
@section("mysection") let invalidVarRef = someVar
99-
// expected-error@-1{{unable to resolve variable reference in a '@const' expression}}
99+
// expected-error@-1{{unable to resolve variable reference in a constant expression}}
100100

101101
struct MyCustomExpressibleByIntegerLiteral: ExpressibleByIntegerLiteral {
102102
init(integerLiteral value: Int) {}
103103
}
104104

105105
// custom types (should be rejected)
106106
@section("mysection") let invalidCustomType1: MyCustomExpressibleByIntegerLiteral = 42
107-
// expected-error@-1{{unsupported type in a '@const' expression}}
107+
// expected-error@-1{{unsupported type in a constant expression}}
108108
@section("mysection") let invalidCustomType2: E = E.a
109-
// expected-error@-1{{not supported in a '@const' expression}}
109+
// expected-error@-1{{not supported in a constant expression}}
110110
@section("mysection") let invalidCustomType3: S = S()
111-
// expected-error@-1{{not supported in a '@const' expression}}
111+
// expected-error@-1{{not supported in a constant expression}}
112112

113113
// other standard types (should be rejected)
114114
@section("mysection") let invalidString = "hello"
115-
// expected-error@-1{{unsupported type in a '@const' expression}}
115+
// expected-error@-1{{unsupported type in a constant expression}}
116116
@section("mysection") let invalidArray = [1, 2, 3]
117-
// expected-error@-1{{unsupported type in a '@const' expression}}
117+
// expected-error@-1{{unsupported type in a constant expression}}
118118
@section("mysection") let invalidDict = ["key": "value"]
119-
// expected-error@-1{{not supported in a '@const' expression}}
119+
// expected-error@-1{{not supported in a constant expression}}
120120

121121
// inline array
122122
@available(SwiftStdlib 6.2, *)
@@ -125,20 +125,20 @@ struct MyCustomExpressibleByIntegerLiteral: ExpressibleByIntegerLiteral {
125125
// invalid inline array (should be rejected)
126126
@available(SwiftStdlib 6.2, *)
127127
@section("mysection") let invalidInlineArray: InlineArray = [1, 2, 3, Int.max]
128-
// expected-error@-1{{not supported in a '@const' expression}}
128+
// expected-error@-1{{not supported in a constant expression}}
129129

130130
// optionals (should be rejected)
131131
@section("mysection") let optional1: Int? = 42
132-
// expected-error@-1{{unsupported type in a '@const' expression}}
132+
// expected-error@-1{{unsupported type in a constant expression}}
133133
@section("mysection") let optional2: Int? = nil
134-
// expected-error@-1{{unsupported type in a '@const' expression}}
134+
// expected-error@-1{{unsupported type in a constant expression}}
135135
@section("mysection") let optional3: Double? = 3.14
136-
// expected-error@-1{{unsupported type in a '@const' expression}}
136+
// expected-error@-1{{unsupported type in a constant expression}}
137137
@section("mysection") let optional4: Bool? = true
138-
// expected-error@-1{{unsupported type in a '@const' expression}}
138+
// expected-error@-1{{unsupported type in a constant expression}}
139139
@section("mysection") let optional5: Bool? = false
140-
// expected-error@-1{{unsupported type in a '@const' expression}}
140+
// expected-error@-1{{unsupported type in a constant expression}}
141141
@section("mysection") let optional6: Int? = 1 + 1
142-
// expected-error@-1{{unsupported type in a '@const' expression}}
142+
// expected-error@-1{{unsupported type in a constant expression}}
143143
@section("mysection") let optional7: Int? = Int.max
144-
// expected-error@-1{{unsupported type in a '@const' expression}}
144+
// expected-error@-1{{unsupported type in a constant expression}}

test/ConstValues/Tuples.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
@const let constGlobal5: (Int, Float) = (42, 42.0)
1212

1313
// Closure call not supported in syntactically-validated mode
14-
@const let constGlobal7: (UInt64, StaticString, @convention(c) ()->Int) = (42, "hi", { return 42 }) // expected-error {{not supported in a '@const' expression}}
14+
@const let constGlobal7: (UInt64, StaticString, @convention(c) ()->Int) = (42, "hi", { return 42 }) // expected-error {{not supported in a constant expression}}

test/Parse/const.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func takeIntConst(@const _ a: Int) {}
2121
struct Article {
2222
let id: String
2323
}
24-
@const let keypath = \Article.id // expected-error{{keypaths not supported in a '@const' expression}}
24+
@const let keypath = \Article.id // expected-error{{keypaths not supported in a constant expression}}
2525

2626
func LocalConstVarUser() -> Int {
2727
@const let localConst = 3
2828
return localConst + 1
2929
}
3030

31-
@const let a: Bool = Bool.random() // expected-error{{not supported in a '@const' expression}}
31+
@const let a: Bool = Bool.random() // expected-error{{not supported in a constant expression}}

0 commit comments

Comments
 (0)