]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use "missing method m" instead of "missing m method"
authorcuiweixie <cuiweixie@gmail.com>
Thu, 22 Sep 2022 04:11:49 +0000 (12:11 +0800)
committerGopher Robot <gobot@golang.org>
Sat, 24 Sep 2022 17:04:15 +0000 (17:04 +0000)
For #55326

Change-Id: I3d0ff7f820f7b2009d1b226abf701b2337fe8cbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/432635
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types2/lookup.go
src/go/types/lookup.go
test/fixedbugs/issue48471.go
test/fixedbugs/issue49005b.go
test/interface/explicit.go
test/switch6.go

index 1deea0ba395d9052808cf8c54f65a4225e5c2bf8..3a158f73337544b67b90e5337306f5f3d78e4321 100644 (file)
@@ -371,12 +371,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method,
 // it may have a pointer receiver, or it may have the correct name except wrong case.
 // check may be nil.
 func (check *Checker) missingMethodReason(V, T Type, m, alt *Func) string {
-       var mname string
-       if check != nil && check.conf.CompilerErrorMessages {
-               mname = m.Name() + " method"
-       } else {
-               mname = "method " + m.Name()
-       }
+       mname := "method " + m.Name()
 
        if alt != nil {
                if m.Name() != alt.Name() {
index 935655853cc3954acc8417b89db3d7af5d7e3feb..cb75c87820b8f6ad07bdae3746001683e5c07297 100644 (file)
@@ -371,12 +371,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method,
 // it may have a pointer receiver, or it may have the correct name except wrong case.
 // check may be nil.
 func (check *Checker) missingMethodReason(V, T Type, m, alt *Func) string {
-       var mname string
-       if check != nil && compilerErrorMessages {
-               mname = m.Name() + " method"
-       } else {
-               mname = "method " + m.Name()
-       }
+       mname := "method " + m.Name()
 
        if alt != nil {
                if m.Name() != alt.Name() {
index 1b843c8a1663ef6574c5899ec670b06e263062f0..8b8d64370aeee054b5179a55f9f44bbb87f53c4b 100644 (file)
@@ -33,22 +33,22 @@ func (T6) m(int) string { return "" }
 func f(I)
 
 func g() {
-       f(new(T)) // ERROR "cannot use new\(T\) \(.*type \*T\) as type I in argument to f:\n\t\*T does not implement I \(missing M method\)"
+       f(new(T)) // ERROR "cannot use new\(T\) \(.*type \*T\) as type I in argument to f:\n\t\*T does not implement I \(missing method M\)"
 
        var i I
-       i = new(T)    // ERROR "cannot use new\(T\) \(.*type \*T\) as type I in assignment:\n\t\*T does not implement I \(missing M method\)"
-       i = I(new(T)) // ERROR "cannot convert new\(T\) \(.*type \*T\) to type I:\n\t\*T does not implement I \(missing M method\)"
-       i = new(T2)   // ERROR "cannot use new\(T2\) \(.*type \*T2\) as type I in assignment:\n\t\*T2 does not implement I \(missing M method\)\n\t\thave m\(int\)\n\t\twant M\(int\)"
+       i = new(T)    // ERROR "cannot use new\(T\) \(.*type \*T\) as type I in assignment:\n\t\*T does not implement I \(missing method M\)"
+       i = I(new(T)) // ERROR "cannot convert new\(T\) \(.*type \*T\) to type I:\n\t\*T does not implement I \(missing method M\)"
+       i = new(T2)   // ERROR "cannot use new\(T2\) \(.*type \*T2\) as type I in assignment:\n\t\*T2 does not implement I \(missing method M\)\n\t\thave m\(int\)\n\t\twant M\(int\)"
 
-       i = new(T3) // ERROR "cannot use new\(T3\) \(.*type \*T3\) as type I in assignment:\n\t\*T3 does not implement I \(wrong type for M method\)\n\t\thave M\(string\)\n\t\twant M\(int\)"
+       i = new(T3) // ERROR "cannot use new\(T3\) \(.*type \*T3\) as type I in assignment:\n\t\*T3 does not implement I \(wrong type for method M\)\n\t\thave M\(string\)\n\t\twant M\(int\)"
 
-       i = T4{}   // ERROR "cannot use T4\{\} \(.*type T4\) as type I in assignment:\n\tT4 does not implement I \(M method has pointer receiver\)"
+       i = T4{}   // ERROR "cannot use T4\{\} \(.*type T4\) as type I in assignment:\n\tT4 does not implement I \(method M has pointer receiver\)"
        i = new(I) // ERROR "cannot use new\(I\) \(.*type \*I\) as type I in assignment:\n\t\*I does not implement I \(type \*I is pointer to interface, not interface\)"
 
-       _ = i.(*T2) // ERROR "impossible type assertion: i.\(\*T2\)\n\t\*T2 does not implement I \(missing M method\)\n\t\thave m\(int\)\n\t\twant M\(int\)"
-       _ = i.(*T3) // ERROR "impossible type assertion: i.\(\*T3\)\n\t\*T3 does not implement I \(wrong type for M method\)\n\t\thave M\(string\)\n\t\twant M\(int\)"
-       _ = i.(T5)  // ERROR ""impossible type assertion: i.\(T5\)\n\tT5 does not implement I \(missing M method\)\n\t\thave m\(int\)\n\t\twant M\(int\)"
-       _ = i.(T6)  // ERROR "impossible type assertion: i.\(T6\)\n\tT6 does not implement I \(missing M method\)\n\t\thave m\(int\) string\n\t\twant M\(int\)"
+       _ = i.(*T2) // ERROR "impossible type assertion: i.\(\*T2\)\n\t\*T2 does not implement I \(missing method M\)\n\t\thave m\(int\)\n\t\twant M\(int\)"
+       _ = i.(*T3) // ERROR "impossible type assertion: i.\(\*T3\)\n\t\*T3 does not implement I \(wrong type for method M\)\n\t\thave M\(string\)\n\t\twant M\(int\)"
+       _ = i.(T5)  // ERROR ""impossible type assertion: i.\(T5\)\n\tT5 does not implement I \(missing method M\)\n\t\thave m\(int\)\n\t\twant M\(int\)"
+       _ = i.(T6)  // ERROR "impossible type assertion: i.\(T6\)\n\tT6 does not implement I \(missing method M\)\n\t\thave m\(int\) string\n\t\twant M\(int\)"
 
        var t *T4
        t = i // ERROR "cannot use i \(variable of type I\) as type \*T4 in assignment:\n\tneed type assertion"
index 9bff4e9d18d65aa08446a932ca461593d67d71ef..61710e01e0c2b98140a47b833b3c4343c36308ce 100644 (file)
@@ -10,6 +10,6 @@ type T interface{ M() }
 
 func F() T
 
-var _ = F().(*X) // ERROR "impossible type assertion:( F\(\).\(\*X\))?\n\t\*X does not implement T \(missing M method\)"
+var _ = F().(*X) // ERROR "impossible type assertion:( F\(\).\(\*X\))?\n\t\*X does not implement T \(missing method M\)"
 
 type X struct{}
index e18d6843ec66ec3efb92893714d46330bf86d322..ccdae7873cf66452ebc9271bb5844fead25a5040 100644 (file)
@@ -43,11 +43,11 @@ func main() {
        // neither of these can work,
        // because i has an extra method
        // that t does not, so i cannot contain a t.
-       i = t // ERROR "incompatible|missing M method"
+       i = t // ERROR "incompatible|missing method M"
        t = i // ERROR "incompatible|assignment$"
 
        i = i2 // ok
-       i2 = i // ERROR "incompatible|missing N method"
+       i2 = i // ERROR "incompatible|missing method N"
 
        i = I(i2)  // ok
        i2 = I2(i) // ERROR "invalid|missing N method|cannot convert"
@@ -81,7 +81,7 @@ var ii int
 var jj Int
 
 var m1 M = ii // ERROR "incompatible|missing"
-var m2 M = jj // ERROR "incompatible|wrong type for M method"
+var m2 M = jj // ERROR "incompatible|wrong type for method M"
 
 var m3 = M(ii) // ERROR "invalid|missing|cannot convert"
 var m4 = M(jj) // ERROR "invalid|wrong type for M method|cannot convert"
index b9d9800391816012d29ab5513c2aa9f8a1416995..fd66df5a5888dac4bcaaf96527501138296ebecd 100644 (file)
@@ -15,7 +15,7 @@ package main
 // Verify that type switch statements with impossible cases are detected by the compiler.
 func f0(e error) {
        switch e.(type) {
-       case int: // ERROR "impossible type switch case: (int\n\t)?e \(.*type error\) cannot have dynamic type int \(missing Error method\)"
+       case int: // ERROR "impossible type switch case: (int\n\t)?e \(.*type error\) cannot have dynamic type int \(missing method Error\)"
        }
 }
 
@@ -41,6 +41,6 @@ func (*X) Foo() {}
 func f2() {
        var i I
        switch i.(type) {
-       case X: // ERROR "impossible type switch case: (X\n\t)?i \(.*type I\) cannot have dynamic type X \(Foo method has pointer receiver\)"
+       case X: // ERROR "impossible type switch case: (X\n\t)?i \(.*type I\) cannot have dynamic type X \(method Foo has pointer receiver\)"
        }
 }