@@ -29,12 +29,12 @@ func main() {
29
29
tmpdir , pkgs := setupPackages (t , code )
30
30
defer teardownPackage (t , tmpdir )
31
31
32
- errs := Run (pkgs )
32
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
33
33
assert .Equal (t , 1 , len (errs ))
34
34
assert .Equal (t , []string {"B" }, missingNames (t , errs [0 ]))
35
35
}
36
36
37
- // TestMissingTwo tests that we detect a two missing variants.
37
+ // TestMissingTwo tests that we detect two missing variants.
38
38
func TestMissingTwo (t * testing.T ) {
39
39
code := `
40
40
package gochecksumtype
@@ -60,7 +60,7 @@ func main() {
60
60
tmpdir , pkgs := setupPackages (t , code )
61
61
defer teardownPackage (t , tmpdir )
62
62
63
- errs := Run (pkgs )
63
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
64
64
assert .Equal (t , 1 , len (errs ))
65
65
assert .Equal (t , []string {"B" , "C" }, missingNames (t , errs [0 ]))
66
66
}
@@ -91,7 +91,7 @@ func main() {
91
91
tmpdir , pkgs := setupPackages (t , code )
92
92
defer teardownPackage (t , tmpdir )
93
93
94
- errs := Run (pkgs )
94
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
95
95
assert .Equal (t , 1 , len (errs ))
96
96
assert .Equal (t , []string {"B" }, missingNames (t , errs [0 ]))
97
97
}
@@ -122,13 +122,13 @@ func main() {
122
122
tmpdir , pkgs := setupPackages (t , code )
123
123
defer teardownPackage (t , tmpdir )
124
124
125
- errs := Run (pkgs )
125
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
126
126
assert .Equal (t , 0 , len (errs ))
127
127
}
128
128
129
- // TestNoMissingDefault tests that even if we have a missing variant, a default
130
- // case should thwart exhaustiveness checking.
131
- func TestNoMissingDefault (t * testing.T ) {
129
+ // TestNoMissingDefaultWithDefaultSignifiesExhaustive tests that even if we have a missing variant, a default
130
+ // case should thwart exhaustiveness checking when Config.DefaultSignifiesExhaustive is true .
131
+ func TestNoMissingDefaultWithDefaultSignifiesExhaustive (t * testing.T ) {
132
132
code := `
133
133
package gochecksumtype
134
134
@@ -152,10 +152,41 @@ func main() {
152
152
tmpdir , pkgs := setupPackages (t , code )
153
153
defer teardownPackage (t , tmpdir )
154
154
155
- errs := Run (pkgs )
155
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
156
156
assert .Equal (t , 0 , len (errs ))
157
157
}
158
158
159
+ // TestNoMissingDefaultAndDefaultDoesNotSignifiesExhaustive tests that even if we have a missing variant, a default
160
+ // case should thwart exhaustiveness checking when Config.DefaultSignifiesExhaustive is false.
161
+ func TestNoMissingDefaultAndDefaultDoesNotSignifiesExhaustive (t * testing.T ) {
162
+ code := `
163
+ package gochecksumtype
164
+
165
+ //sumtype:decl
166
+ type T interface { sealed() }
167
+
168
+ type A struct {}
169
+ func (a *A) sealed() {}
170
+
171
+ type B struct {}
172
+ func (b *B) sealed() {}
173
+
174
+ func main() {
175
+ switch T(nil).(type) {
176
+ case *A:
177
+ default:
178
+ println("legit catch all goes here")
179
+ }
180
+ }
181
+ `
182
+ tmpdir , pkgs := setupPackages (t , code )
183
+ defer teardownPackage (t , tmpdir )
184
+
185
+ errs := Run (pkgs , Config {DefaultSignifiesExhaustive : false })
186
+ assert .Equal (t , 1 , len (errs ))
187
+ assert .Equal (t , []string {"B" }, missingNames (t , errs [0 ]))
188
+ }
189
+
159
190
// TestNotSealed tests that we report an error if one tries to declare a sum
160
191
// type with an unsealed interface.
161
192
func TestNotSealed (t * testing.T ) {
@@ -170,7 +201,7 @@ func main() {}
170
201
tmpdir , pkgs := setupPackages (t , code )
171
202
defer teardownPackage (t , tmpdir )
172
203
173
- errs := Run (pkgs )
204
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
174
205
assert .Equal (t , 1 , len (errs ))
175
206
assert .Equal (t , "T" , errs [0 ].(unsealedError ).Decl .TypeName )
176
207
}
@@ -189,7 +220,7 @@ func main() {}
189
220
tmpdir , pkgs := setupPackages (t , code )
190
221
defer teardownPackage (t , tmpdir )
191
222
192
- errs := Run (pkgs )
223
+ errs := Run (pkgs , Config { DefaultSignifiesExhaustive : true } )
193
224
assert .Equal (t , 1 , len (errs ))
194
225
assert .Equal (t , "T" , errs [0 ].(notInterfaceError ).Decl .TypeName )
195
226
}
0 commit comments