1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:36:15 -07:00

go/types: use function name position for init errors

This seems more sensible than the func keyword. With this change,
go/types uses the same error position as types2 and we can narrow
the error tolerance a bit.

(The types2 change doesn't change its position, but it makes the
code clearer and symmetric to go/types.)

Change-Id: Iedea7c80caa7239a4343c8748cb779ec545e84d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/427775
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-09-01 20:47:41 -07:00 committed by Robert Griesemer
parent 321a220d50
commit 5befb24bb5
5 changed files with 8 additions and 8 deletions

View File

@ -299,7 +299,7 @@ func TestManual(t *testing.T) {
func TestCheck(t *testing.T) {
DefPredeclaredTestFuncs()
testDirFiles(t, "../../../../internal/types/testdata/check", 55, false) // TODO(gri) narrow column tolerance
testDirFiles(t, "../../../../internal/types/testdata/check", 50, false) // TODO(gri) narrow column tolerance
}
func TestSpec(t *testing.T) { testDirFiles(t, "../../../../internal/types/testdata/spec", 0, false) }
func TestExamples(t *testing.T) {

View File

@ -421,7 +421,7 @@ func (check *Checker) collectObjects() {
hasTParamError = true
}
if t := s.Type; len(t.ParamList) != 0 || len(t.ResultList) != 0 {
check.softErrorf(s, "func %s must have no arguments and no return values", name)
check.softErrorf(s.Name, "func %s must have no arguments and no return values", name)
}
}
// don't declare init functions in the package scope - they are invisible

View File

@ -411,7 +411,7 @@ func (check *Checker) collectObjects() {
}
if t := d.decl.Type; t.Params.NumFields() != 0 || t.Results != nil {
// TODO(rFindley) Should this be a hard error?
check.softErrorf(d.decl, code, "func %s must have no arguments and no return values", name)
check.softErrorf(d.decl.Name, code, "func %s must have no arguments and no return values", name)
}
}
if name == "init" {

View File

@ -140,7 +140,7 @@ func (x *T) m3() {}
// Initialization functions
func init() {}
func /* ERROR "no arguments and no return values" */ init(int) {}
func /* ERROR "no arguments and no return values" */ init() int { return 0 }
func /* ERROR "no arguments and no return values" */ init(int) int { return 0 }
func init /* ERROR "no arguments and no return values" */ (int) {}
func init /* ERROR "no arguments and no return values" */ () int { return 0 }
func init /* ERROR "no arguments and no return values" */ (int) int { return 0 }
func (T) init(int) int { return 0 }

View File

@ -5,5 +5,5 @@
package main
func main()
func /* ERROR "no arguments and no return values" */ main /* ERROR redeclared */ (int)
func /* ERROR "no arguments and no return values" */ main /* ERROR redeclared */ () int
func main /* ERROR "no arguments and no return values" */ /* ERROR redeclared */ (int)
func main /* ERROR "no arguments and no return values" */ /* ERROR redeclared */ () int