]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: use function name position for init errors
authorRobert Griesemer <gri@golang.org>
Fri, 2 Sep 2022 03:47:41 +0000 (20:47 -0700)
committerRobert Griesemer <gri@google.com>
Fri, 2 Sep 2022 16:43:15 +0000 (16:43 +0000)
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>

src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/resolver.go
src/go/types/resolver.go
src/internal/types/testdata/check/decls1.go
src/internal/types/testdata/check/main0.go

index b0ec1f536cfeb4e5b90e7d5951edf70ec4fca174..98813ad5a7695517afaf57d9021538c89b0be444 100644 (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) {
index 77881f493f6749fd3bd93fccb6eae89423b559f8..b7ba083627da554c75ad578de3c3c90c325873df 100644 (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
index c4a973a5b9df711bd8690f3ff42831285d6930e2..12ec55a144259fe9f47827cf8a62dd8c726255cb 100644 (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" {
index 6fe349b0b2fda71f7c6369ed4f139b6bc4737496..4052c869257bfd127780bdcdf707bf4c473692f2 100644 (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 }
index f892938d4acfa878617ea78f61e28139fd7de013..132a5fec4557e76a2613cbc7935c5f2910ed9702 100644 (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