// typechecking
conf := types2.Config{
InferFromConstraints: true,
- IgnoreBranches: true, // parser already checked via syntax.CheckBranches mode
+ IgnoreLabels: true, // parser already checked via syntax.CheckBranches mode
CompilerErrorMessages: true, // use error strings matching existing compiler errors
Error: func(err error) {
terr := err.(types2.Error)
// Do not use casually!
FakeImportC bool
- // If IgnoreBranches is set, errors related to incorrectly placed
- // labels, gotos, break, continue, and fallthrough statements are
- // ignored.
- IgnoreBranches bool
+ // If IgnoreLabels is set, correct label use is not checked.
+ // TODO(gri) Consolidate label checking and remove this flag.
+ IgnoreLabels bool
// If CompilerErrorMessages is set, errors are reported using
// cmd/compile error strings to match $GOROOT/test errors.
check.stmtList(0, body.List)
- if check.hasLabel {
- assert(!check.conf.IgnoreBranches)
+ if check.hasLabel && !check.conf.IgnoreLabels {
check.labels(body)
}
check.declStmt(s.DeclList)
case *syntax.LabeledStmt:
- check.hasLabel = !check.conf.IgnoreBranches
+ check.hasLabel = true
check.stmt(ctxt, s.Stmt)
case *syntax.ExprStmt:
}
case *syntax.BranchStmt:
- if check.conf.IgnoreBranches {
- break
- }
-
if s.Label != nil {
check.hasLabel = true
- return // checked in 2nd pass (check.labels)
+ break // checked in 2nd pass (check.labels)
}
switch s.Tok {
case syntax.Break:
if ctxt&breakOk == 0 {
- check.error(s, "break not in for, switch, or select statement")
+ if check.conf.CompilerErrorMessages {
+ check.error(s, "break is not in a loop, switch, or select statement")
+ } else {
+ check.error(s, "break not in for, switch, or select statement")
+ }
}
case syntax.Continue:
if ctxt&continueOk == 0 {
- check.error(s, "continue not in for statement")
+ if check.conf.CompilerErrorMessages {
+ check.error(s, "continue is not in a loop")
+ } else {
+ check.error(s, "continue not in for statement")
+ }
}
case syntax.Fallthrough:
if ctxt&fallthroughOk == 0 {
"initializerr.go": true, // types2 reports extra errors
"linkname2.go": true, // error reported by noder (not running for types2 errorcheck test)
"shift1.go": true, // issue #42989
- "switch4.go": true, // error reported by noder (not running for types2 errorcheck test)
"typecheck.go": true, // invalid function is not causing errors when called
"fixedbugs/bug176.go": true, // types2 reports all errors (pref: types2)
"fixedbugs/bug193.go": true, // types2 bug: shift error not reported (fixed in go/types)
"fixedbugs/bug195.go": true, // types2 reports slightly different (but correct) bugs
- "fixedbugs/bug213.go": true, // error reported by noder (not running for types2 errorcheck test)
"fixedbugs/bug228.go": true, // types2 not run after syntax errors
"fixedbugs/bug231.go": true, // types2 bug? (same error reported twice)
"fixedbugs/bug255.go": true, // types2 reports extra errors
"fixedbugs/issue4232.go": true, // types2 reports (correct) extra errors
"fixedbugs/issue4452.go": true, // types2 reports (correct) extra errors
"fixedbugs/issue5609.go": true, // types2 needs a better error message
- "fixedbugs/issue6500.go": true, // error reported by noder (not running for types2 errorcheck test)
"fixedbugs/issue6889.go": true, // types2 can handle this without constant overflow
"fixedbugs/issue7525.go": true, // types2 reports init cycle error on different line - ok otherwise
"fixedbugs/issue7525b.go": true, // types2 reports init cycle error on different line - ok otherwise