File tree 4 files changed +41
-1
lines changed 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,13 @@ func (e *TypeAssertionError) Error() string {
36
36
return "interface conversion: " + inter + " is nil, not " + e .assertedString
37
37
}
38
38
if e .missingMethod == "" {
39
- return "interface conversion: " + inter + " is " + e .concreteString +
39
+ msg := "interface conversion: " + inter + " is " + e .concreteString +
40
40
", not " + e .assertedString
41
+ if e .concreteString == e .assertedString {
42
+ // provide slightly clearer error message
43
+ msg += " (types from different packages)"
44
+ }
45
+ return msg
41
46
}
42
47
return "interface conversion: " + e .concreteString + " is not " + e .assertedString +
43
48
": missing method " + e .missingMethod
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package a
6
+
7
+ var X interface {} = struct { x int }{}
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package main
6
+
7
+ import "./a"
8
+ import "strings"
9
+
10
+ func main () {
11
+ defer func () {
12
+ p , ok := recover ().(error )
13
+ if ok && strings .Contains (p .Error (), "different packages" ) {
14
+ return
15
+ }
16
+ panic (p )
17
+ }()
18
+
19
+ // expected to fail and report two identical looking (but different) types
20
+ _ = a .X .(struct { x int })
21
+ }
Original file line number Diff line number Diff line change
1
+ // rundir
2
+
3
+ // Copyright 2018 The Go Authors. All rights reserved.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package ignore
You can’t perform that action at this time.
0 commit comments