-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
879cdef
commit 13ee94a
Showing
7 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
testdata/src/default-case-required/default-not-required/default_not_required.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package notrequired | ||
|
||
import "default-case-required" | ||
|
||
func _a(t dcr.T) { | ||
// No diagnostic because neither fDefaultCaseRequired is true | ||
// nor the enforcement comment is present. | ||
switch t { | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _b(t dcr.T) { | ||
//exhaustive:enforce-default-case-required this is a comment showing that we can turn it on for select switches | ||
switch t { // want "^missing default case in switch of type dcr.T$" | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _c(t dcr.T) { | ||
//exhaustive:ignore-default-case-required this comment is discarded in facvor of the enforcement | ||
//exhaustive:enforce-default-case-required this is a comment showing that we can turn it on for select switches | ||
switch t { // want "^missing default case in switch of type dcr.T$" | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _d(t dcr.T) { | ||
//exhaustive:enforce-default-case-required this is a comment showing that we can turn it on for select switches | ||
//exhaustive:ignore-default-case-required this comment is discarded in facvor of the enforcement | ||
switch t { // want "^missing default case in switch of type dcr.T$" | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _e(t dcr.T) { | ||
//exhaustive:enforce-default-case-required this is happy because it has a default | ||
switch t { | ||
case dcr.A: | ||
case dcr.B: | ||
default: | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
testdata/src/default-case-required/default-required/default_required.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package required | ||
|
||
import "default-case-required" | ||
|
||
func _a(t dcr.T) { | ||
// expect a diagnostic when fDefaultCaseRequired is true. | ||
switch t { // want "^missing default case in switch of type dcr.T$" | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _b(t dcr.T) { | ||
//exhaustive:ignore-default-case-required this is a comment showing that we can turn it off for select switches | ||
switch t { | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _c(t dcr.T) { | ||
//exhaustive:ignore-default-case-required this comment is discarded in facvor of the enforcement | ||
//exhaustive:enforce-default-case-required this helps override the above | ||
switch t { // want "^missing default case in switch of type dcr.T$" | ||
case dcr.A: | ||
case dcr.B: | ||
} | ||
} | ||
|
||
func _d(t dcr.T) { | ||
// this is happy even with enforcement because we have a default | ||
switch t { | ||
case dcr.A: | ||
case dcr.B: | ||
default: | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dcr | ||
|
||
type T int | ||
|
||
const ( | ||
A T = iota | ||
B | ||
) |