1
- // RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s 2>&1 | %FileCheck %s
1
+ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -verify
2
2
3
3
// Codable class with non-Codable property.
4
4
class C1 : Codable {
5
+ // expected-error@-1 {{type 'C1' does not conform to protocol 'Decodable'}}
6
+ // expected-error@-2 {{type 'C1' does not conform to protocol 'Encodable'}}
7
+
5
8
class Nested { }
6
9
var a : String = " "
7
10
var b : Int = 0
8
11
var c : Nested = Nested ( )
9
-
10
- // CHECK: error: type 'C1' does not conform to protocol 'Decodable'
11
- // CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
12
- // CHECK: note: cannot automatically synthesize 'Decodable' because 'C1.Nested' does not conform to 'Decodable'
13
-
14
- // CHECK: error: type 'C1' does not conform to protocol 'Encodable'
15
- // CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
16
- // CHECK: note: cannot automatically synthesize 'Encodable' because 'C1.Nested' does not conform to 'Encodable'
12
+ // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'C1.Nested' does not conform to 'Decodable'}}
13
+ // expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'C1.Nested' does not conform to 'Encodable'}}
17
14
}
18
15
19
16
// Codable class with non-enum CodingKeys.
20
17
class C2 : Codable {
18
+ // expected-error@-1 {{type 'C2' does not conform to protocol 'Decodable'}}
19
+ // expected-error@-2 {{type 'C2' does not conform to protocol 'Encodable'}}
20
+
21
21
var a : String = " "
22
22
var b : Int = 0
23
23
var c : Double ?
24
24
25
25
struct CodingKeys : CodingKey {
26
+ // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum}}
27
+ // expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum}}
26
28
var stringValue = " "
27
29
var intValue = nil
30
+ // expected-error@-1 {{'nil' requires a contextual type}}
28
31
init ? ( stringValue: String ) { }
29
32
init ? ( intValue: Int ) { }
30
33
}
31
-
32
- // CHECK: error: type 'C2' does not conform to protocol 'Decodable'
33
- // CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
34
- // CHECK: note: cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum
35
-
36
- // CHECK: error: type 'C2' does not conform to protocol 'Encodable'
37
- // CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
38
- // CHECK: note: cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum
39
34
}
40
35
41
36
// Codable class with CodingKeys not conforming to CodingKey.
42
37
class C3 : Codable {
38
+ // expected-error@-1 {{type 'C3' does not conform to protocol 'Decodable'}}
39
+ // expected-error@-2 {{type 'C3' does not conform to protocol 'Encodable'}}
40
+
43
41
var a : String = " "
44
42
var b : Int = 0
45
43
var c : Double ?
46
44
47
45
enum CodingKeys : String {
46
+ // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey}}
47
+ // expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey}}
48
48
case a
49
49
case b
50
50
case c
51
51
}
52
-
53
- // CHECK: error: type 'C3' does not conform to protocol 'Decodable'
54
- // CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
55
- // CHECK: note: cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey
56
-
57
- // CHECK: error: type 'C3' does not conform to protocol 'Encodable'
58
- // CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
59
- // CHECK: note: cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey
60
52
}
61
53
62
54
// Codable class with extraneous CodingKeys
63
55
class C4 : Codable {
56
+ // expected-error@-1 {{type 'C4' does not conform to protocol 'Decodable'}}
57
+ // expected-error@-2 {{type 'C4' does not conform to protocol 'Encodable'}}
58
+
64
59
var a : String = " "
65
60
var b : Int = 0
66
61
var c : Double ?
67
62
68
63
enum CodingKeys : String , CodingKey {
69
64
case a
70
65
case a2
66
+ // expected-note@-1 2{{CodingKey case 'a2' does not match any stored properties}}
71
67
case b
72
68
case b2
69
+ // expected-note@-1 2{{CodingKey case 'b2' does not match any stored properties}}
73
70
case c
74
71
case c2
72
+ // expected-note@-1 2{{CodingKey case 'c2' does not match any stored properties}}
75
73
}
76
-
77
- // CHECK: error: type 'C4' does not conform to protocol 'Decodable'
78
- // CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
79
- // CHECK: note: CodingKey case 'a2' does not match any stored properties
80
- // CHECK: note: CodingKey case 'b2' does not match any stored properties
81
- // CHECK: note: CodingKey case 'c2' does not match any stored properties
82
-
83
- // CHECK: error: type 'C4' does not conform to protocol 'Encodable'
84
- // CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
85
- // CHECK: note: CodingKey case 'a2' does not match any stored properties
86
- // CHECK: note: CodingKey case 'b2' does not match any stored properties
87
- // CHECK: note: CodingKey case 'c2' does not match any stored properties
88
74
}
89
75
90
76
// Codable class with non-decoded property (which has no default value).
91
77
class C5 : Codable {
78
+ // expected-error@-1 {{type 'C5' does not conform to protocol 'Decodable'}}
79
+ // expected-error@-2 {{class 'C5' has no initializers}}
80
+
92
81
var a : String = " "
93
82
var b : Int
83
+ // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value}}
84
+ // expected-note@-2 {{stored property 'b' without initial value prevents synthesized initializers}}
94
85
var c : Double ?
95
86
96
87
enum CodingKeys : String , CodingKey {
97
88
case a
98
89
case c
99
90
}
100
-
101
- // CHECK: error: type 'C5' does not conform to protocol 'Decodable'
102
- // CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
103
- // CHECK: note: cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value
104
-
105
- // CHECK: error: class 'C5' has no initializers
106
- // CHECK: note: stored property 'b' without initial value prevents synthesized initializers
107
91
}
108
92
109
93
// Codable class with non-decoded property (which has no default value).
110
94
class C6 : Codable {
95
+ // expected-error@-1 {{type 'C6' does not conform to protocol 'Decodable'}}
96
+
111
97
var a : String = " "
112
98
var b : Int
99
+ // expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value}}
113
100
var c : Double ?
114
101
115
102
enum CodingKeys : String , CodingKey {
@@ -120,14 +107,10 @@ class C6 : Codable {
120
107
init ( ) {
121
108
b = 5
122
109
}
123
-
124
- // CHECK: error: type 'C6' does not conform to protocol 'Decodable'
125
- // CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
126
- // CHECK: note: cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value
127
110
}
128
111
129
112
// Classes cannot yet synthesize Encodable or Decodable in extensions.
130
113
class C7 { }
131
114
extension C7 : Codable { }
132
- // CHECK: error: implementation of 'Decodable' cannot be automatically synthesized in an extension
133
- // CHECK: error: implementation of 'Encodable' cannot be automatically synthesized in an extension
115
+ // expected- error@-1 {{ implementation of 'Decodable' cannot be automatically synthesized in an extension}}
116
+ // expected- error@-2 {{ implementation of 'Encodable' cannot be automatically synthesized in an extension}}
0 commit comments