|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | + |
| 3 | +class ClassWithNonExcludedLetMembers : Codable { // expected-error {{class 'ClassWithNonExcludedLetMembers' has no initializers}} |
| 4 | + // expected-error@-1 {{type 'ClassWithNonExcludedLetMembers' does not conform to protocol 'Decodable'}} |
| 5 | + // expected-error@-2 {{type 'ClassWithNonExcludedLetMembers' does not conform to protocol 'Encodable'}} |
| 6 | + |
| 7 | + // Optional `let`s do not get an implicit nil assignment. |
| 8 | + let p1: String? // expected-note {{stored property 'p1' without initial value prevents synthesized initializers}} |
| 9 | + let p2: String! // expected-note {{stored property 'p2' without initial value prevents synthesized initializers}} |
| 10 | + |
| 11 | + // AnyHashable does not conform to Codable. |
| 12 | + let p3: AnyHashable? // expected-note {{stored property 'p3' without initial value prevents synthesized initializers}} |
| 13 | + // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}} |
| 14 | + // expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}} |
| 15 | + let p4: AnyHashable? // expected-note {{stored property 'p4' without initial value prevents synthesized initializers}} |
| 16 | + // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}} |
| 17 | + // expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}} |
| 18 | +} |
| 19 | + |
| 20 | +class ClassWithExcludedLetMembers : Codable { // expected-error {{class 'ClassWithExcludedLetMembers' has no initializers}} |
| 21 | + // expected-error@-1 {{type 'ClassWithExcludedLetMembers' does not conform to protocol 'Decodable'}} |
| 22 | + |
| 23 | + // Optional `let`s do not get an implicit nil assignment. |
| 24 | + let p1: String? // expected-note {{stored property 'p1' without initial value prevents synthesized initializers}} |
| 25 | + let p2: String! // expected-note {{stored property 'p2' without initial value prevents synthesized initializers}} |
| 26 | + |
| 27 | + // AnyHashable does not conform to Codable. |
| 28 | + let p3: AnyHashable? // expected-note {{stored property 'p3' without initial value prevents synthesized initializers}} |
| 29 | + // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'p3' does not have a matching CodingKey and does not have a default value}} |
| 30 | + let p4: AnyHashable? // expected-note {{stored property 'p4' without initial value prevents synthesized initializers}} |
| 31 | + // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'p4' does not have a matching CodingKey and does not have a default value}} |
| 32 | + |
| 33 | + // Explicitly exclude non-Codable properties. |
| 34 | + enum CodingKeys : String, CodingKey { |
| 35 | + case p1, p2 |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +class ClassWithNonExcludedVarMembers : Codable { // expected-error {{type 'ClassWithNonExcludedVarMembers' does not conform to protocol 'Decodable'}} |
| 40 | + // expected-error@-1 {{type 'ClassWithNonExcludedVarMembers' does not conform to protocol 'Encodable'}} |
| 41 | + |
| 42 | + var p1: String? |
| 43 | + var p2: String! |
| 44 | + |
| 45 | + // AnyHashable does not conform to Codable. |
| 46 | + var p3: AnyHashable? // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}} |
| 47 | + // expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}} |
| 48 | + var p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable!' does not conform to 'Decodable'}} |
| 49 | + // expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable!' does not conform to 'Encodable'}} |
| 50 | +} |
| 51 | + |
| 52 | +class ClassWithExcludedVarMembers : Codable { |
| 53 | + var p1: String? |
| 54 | + var p2: String! |
| 55 | + |
| 56 | + // AnyHashable does not conform to Codable. |
| 57 | + var p3: AnyHashable? |
| 58 | + var p4: AnyHashable! |
| 59 | + |
| 60 | + // Explicitly exclude non-Codable properties. |
| 61 | + enum CodingKeys : String, CodingKey { |
| 62 | + case p1, p2 |
| 63 | + } |
| 64 | +} |
0 commit comments