mirror of
https://github.com/golang/go
synced 2024-11-22 14:44:50 -07:00
7398c3c0c6
Compromise between old compiler error "T.m redeclared in this block" (where the "in this block" is not particularly helpful) and the old type-checker error "method m already declared for type T ...". In the case where we have position information for the original declaration, the error message is "method T.m already declared at <position>". The new message is both shorter and more precise. For #55326. Change-Id: Id4a7f326fe631b11db9e8030eccb417c72d6c7db Reviewed-on: https://go-review.googlesource.com/c/go/+/435016 Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
25 lines
739 B
Go
25 lines
739 B
Go
// errorcheck
|
|
|
|
// Copyright 2009 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 method redeclarations are caught by the compiler.
|
|
// Does not compile.
|
|
|
|
package main
|
|
|
|
type T struct{}
|
|
|
|
func (t *T) M(int, string) // GCCGO_ERROR "previous"
|
|
func (t *T) M(int, float64) {} // ERROR "already declared|redefinition"
|
|
|
|
func (t T) H() // GCCGO_ERROR "previous"
|
|
func (t *T) H() {} // ERROR "already declared|redefinition"
|
|
|
|
func f(int, string) // GCCGO_ERROR "previous"
|
|
func f(int, float64) {} // ERROR "redeclared|redefinition"
|
|
|
|
func g(a int, b string) // GCCGO_ERROR "previous"
|
|
func g(a int, c string) // ERROR "redeclared|redefinition"
|