1
0
mirror of https://github.com/golang/go synced 2024-11-22 15:34:53 -07:00
go/test/switch2.go
Robert Griesemer 2eac154b1c cmd/compile: better error message when offending/missing token is a keyword
Prefix keywords (type, default, case, etc.) with "keyword" in error
messages to make them less ambiguous.

Fixes #68589.

Change-Id: I1eb92d1382f621b934167b3a4c335045da26be9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/623819
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
2024-11-14 02:14:13 +00:00

40 lines
791 B
Go

// errorcheck
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Verify that erroneous switch statements are detected by the compiler.
// Does not compile.
package main
func f() {
switch {
case 0; // ERROR "expecting := or = or : or comma|expected :"
}
switch {
case 0; // ERROR "expecting := or = or : or comma|expected :"
default:
}
switch {
case 0: case 0: default:
}
switch {
case 0: f(); case 0:
case 0: f() case 0: // ERROR "unexpected keyword case at end of statement"
}
switch {
case 0: f(); default:
case 0: f() default: // ERROR "unexpected keyword default at end of statement"
}
switch {
if x: // ERROR "expected case or default or }"
}
}