Skip to content

Commit 3082bbf

Browse files
authored
Merge pull request #20002 from adamshin/enum-raw-type-message
[sema] Fix error message for enums with an invalid raw type
2 parents 925c93a + c7e80eb commit 3082bbf

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,7 @@ ERROR(multiple_enum_raw_types,none,
22772277
ERROR(raw_type_not_first,none,
22782278
"raw type %0 must appear first in the enum inheritance clause", (Type))
22792279
ERROR(raw_type_not_literal_convertible,none,
2280-
"raw type %0 is not expressible by any literal",
2280+
"raw type %0 is not expressible by a string, integer, or floating-point literal",
22812281
(Type))
22822282
ERROR(enum_raw_type_not_equatable,none,
22832283
"RawRepresentable conformance cannot be synthesized because raw type %0 is not "

test/Generics/inheritance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func testGenericInherit() {
5656

5757

5858
struct SS<T> : T { } // expected-error{{inheritance from non-protocol type 'T'}}
59-
enum SE<T> : T { case X } // expected-error{{raw type 'T' is not expressible by any literal}} // expected-error {{SE<T>' declares raw type 'T', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error{{RawRepresentable conformance cannot be synthesized because raw type 'T' is not Equatable}}
59+
enum SE<T> : T { case X } // expected-error{{raw type 'T' is not expressible by a string, integer, or floating-point literal}} // expected-error {{SE<T>' declares raw type 'T', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error{{RawRepresentable conformance cannot be synthesized because raw type 'T' is not Equatable}}
6060

6161
// Also need Equatable for init?(RawValue)
6262
enum SE2<T : ExpressibleByIntegerLiteral>

test/IDE/print_ast_tc_decls_errors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} //
119119
// NO-TYREPR: {{^}}enum EnumWithInheritance2 : <<error type>>, <<error type>> {{{$}}
120120
// TYREPR: {{^}}enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}}
121121

122-
enum EnumWithInheritance3 : FooClass { case X } // expected-error {{raw type 'FooClass' is not expressible by any literal}}
122+
enum EnumWithInheritance3 : FooClass { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}}
123123
// expected-error@-1{{'EnumWithInheritance3' declares raw type 'FooClass', but does not conform to RawRepresentable and conformance could not be synthesized}}
124124
// expected-error@-2{{RawRepresentable conformance cannot be synthesized because raw type 'FooClass' is not Equatable}}
125125
// NO-TYREPR: {{^}}enum EnumWithInheritance3 : <<error type>> {{{$}}
126126
// TYREPR: {{^}}enum EnumWithInheritance3 : FooClass {{{$}}
127127

128-
enum EnumWithInheritance4 : FooClass, FooProtocol { case X } // expected-error {{raw type 'FooClass' is not expressible by any literal}}
128+
enum EnumWithInheritance4 : FooClass, FooProtocol { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}}
129129
// expected-error@-1{{'EnumWithInheritance4' declares raw type 'FooClass', but does not conform to RawRepresentable and conformance could not be synthesized}}
130130
// expected-error@-2{{RawRepresentable conformance cannot be synthesized because raw type 'FooClass' is not Equatable}}
131131
// NO-TYREPR: {{^}}enum EnumWithInheritance4 : <<error type>>, FooProtocol {{{$}}
132132
// TYREPR: {{^}}enum EnumWithInheritance4 : FooClass, FooProtocol {{{$}}
133133

134-
enum EnumWithInheritance5 : FooClass, BarClass { case X } // expected-error {{raw type 'FooClass' is not expressible by any literal}} expected-error {{multiple enum raw types 'FooClass' and 'BarClass'}}
134+
enum EnumWithInheritance5 : FooClass, BarClass { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}} expected-error {{multiple enum raw types 'FooClass' and 'BarClass'}}
135135
// expected-error@-1{{'EnumWithInheritance5' declares raw type 'FooClass', but does not conform to RawRepresentable and conformance could not be synthesized}}
136136
// expected-error@-2{{RawRepresentable conformance cannot be synthesized because raw type 'FooClass' is not Equatable}}
137137
// NO-TYREPR: {{^}}enum EnumWithInheritance5 : <<error type>>, <<error type>> {{{$}}

test/Parse/enum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ enum RawTypeNotFirst : RawTypeNotFirstProtocol, Int { // expected-error {{raw ty
143143
case E
144144
}
145145

146-
enum ExpressibleByRawTypeNotLiteral : Array<Int> { // expected-error {{raw type 'Array<Int>' is not expressible by any literal}}
146+
enum ExpressibleByRawTypeNotLiteral : Array<Int> { // expected-error {{raw type 'Array<Int>' is not expressible by a string, integer, or floating-point literal}}
147147
// expected-error@-1{{'ExpressibleByRawTypeNotLiteral' declares raw type 'Array<Int>', but does not conform to RawRepresentable and conformance could not be synthesized}}
148148
case Ladd, Elliott, Sixteenth, Harrison
149149
}

test/Sema/accessibility_private.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ extension Container {
194194
fileprivate subscript(_: VeryPrivateStruct) -> Void { return () } // expected-error {{subscript cannot be declared fileprivate because its index uses a private type}} {{none}}
195195
fileprivate func privateMethod(_: VeryPrivateStruct) -> Void {} // expected-error {{method cannot be declared fileprivate because its parameter uses a private type}} {{none}}
196196
fileprivate enum PrivateRawValue: VeryPrivateStruct {} // expected-error {{enum cannot be declared fileprivate because its raw type uses a private type}} {{none}}
197-
// expected-error@-1 {{raw type 'Container.VeryPrivateStruct' is not expressible by any literal}}
197+
// expected-error@-1 {{raw type 'Container.VeryPrivateStruct' is not expressible by a string, integer, or floating-point literal}}
198198
// expected-error@-2 {{'Container.PrivateRawValue' declares raw type 'Container.VeryPrivateStruct', but does not conform to RawRepresentable and conformance could not be synthesized}}
199199
// expected-error@-3 {{RawRepresentable conformance cannot be synthesized because raw type 'Container.VeryPrivateStruct' is not Equatable}}
200200
fileprivate enum PrivatePayload {

test/Sema/enum_raw_representable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Outer {
7777
// scenario too.
7878
let a: Int = E.a // expected-error {{cannot convert value of type 'Outer.E' to specified type 'Int'}}
7979

80-
enum E : Array<Int> { // expected-error {{raw type 'Array<Int>' is not expressible by any literal}}
80+
enum E : Array<Int> { // expected-error {{raw type 'Array<Int>' is not expressible by a string, integer, or floating-point literal}}
8181
case a
8282
}
8383
}
@@ -185,6 +185,6 @@ func sr8150_mutable(obj: SR8150Box) {
185185
struct NotEquatable { }
186186

187187
enum ArrayOfNewEquatable : Array<NotEquatable> { }
188-
// expected-error@-1{{raw type 'Array<NotEquatable>' is not expressible by any literal}}
188+
// expected-error@-1{{raw type 'Array<NotEquatable>' is not expressible by a string, integer, or floating-point literal}}
189189
// expected-error@-2{{'ArrayOfNewEquatable' declares raw type 'Array<NotEquatable>', but does not conform to RawRepresentable and conformance could not be synthesized}}
190190
// expected-error@-3{{RawRepresentable conformance cannot be synthesized because raw type 'Array<NotEquatable>' is not Equatable}}

0 commit comments

Comments
 (0)