import (
"fmt"
+ "regexp"
"sort"
"cmd/compile/internal/base"
"cmd/internal/src"
)
+var versionErrorRx = regexp.MustCompile(`requires go[0-9]+\.[0-9]+ or later`)
+
// checkFiles configures and runs the types2 checker on the given
// parsed source files and then returns the result.
func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
CompilerErrorMessages: true, // use error strings matching existing compiler errors
Error: func(err error) {
terr := err.(types2.Error)
- base.ErrorfAt(m.makeXPos(terr.Pos), "%s", terr.Msg)
+ msg := terr.Msg
+ // if we have a version error, hint at the -lang setting
+ if versionErrorRx.MatchString(msg) {
+ msg = fmt.Sprintf("%s (-lang was set to %s; check go.mod)", msg, base.Flag.Lang)
+ }
+ base.ErrorfAt(m.makeXPos(terr.Pos), "%s", msg)
},
Importer: &importer,
Sizes: &gcSizes{},
package types2
import (
- "fmt"
"go/constant"
"unicode"
)
if cause != nil {
// TODO(gri) consider restructuring versionErrorf so we can use it here and below
*cause = "conversion of slices to arrays requires go1.20 or later"
- if check.conf.CompilerErrorMessages {
- *cause += fmt.Sprintf(" (-lang was set to %s; check go.mod)", check.conf.GoVersion)
- }
}
return false
}
// check != nil
if cause != nil {
*cause = "conversion of slices to array pointers requires go1.17 or later"
- if check.conf.CompilerErrorMessages {
- *cause += fmt.Sprintf(" (-lang was set to %s; check go.mod)", check.conf.GoVersion)
- }
}
return false
}
func (check *Checker) versionErrorf(at poser, goVersion string, format string, args ...interface{}) {
msg := check.sprintf(format, args...)
- if check.conf.CompilerErrorMessages {
- msg = fmt.Sprintf("%s requires %s or later (-lang was set to %s; check go.mod)", msg, goVersion, check.conf.GoVersion)
- } else {
- msg = fmt.Sprintf("%s requires %s or later", msg, goVersion)
- }
+ msg = fmt.Sprintf("%s requires %s or later", msg, goVersion)
check.err(at, _UnsupportedFeature, msg, true)
}
package types
import (
- "fmt"
"go/constant"
"go/token"
"unicode"
if cause != nil {
// TODO(gri) consider restructuring versionErrorf so we can use it here and below
*cause = "conversion of slices to arrays requires go1.20 or later"
- if compilerErrorMessages {
- *cause += fmt.Sprintf(" (-lang was set to %s; check go.mod)", check.conf.GoVersion)
- }
}
return false
}
// check != nil
if cause != nil {
*cause = "conversion of slices to array pointers requires go1.17 or later"
- if compilerErrorMessages {
- *cause += fmt.Sprintf(" (-lang was set to %s; check go.mod)", check.conf.GoVersion)
- }
}
return false
}
func (check *Checker) versionErrorf(at positioner, code errorCode, goVersion string, format string, args ...interface{}) {
msg := check.sprintf(format, args...)
var err *error_
- if compilerErrorMessages {
- err = newErrorf(at, code, "%s requires %s or later (-lang was set to %s; check go.mod)", msg, goVersion, check.conf.GoVersion)
- } else {
- err = newErrorf(at, code, "%s requires %s or later", msg, goVersion)
- }
+ err = newErrorf(at, code, "%s requires %s or later", msg, goVersion)
check.report(err)
}