compiler: add support for anonymous type asserts

This is used for example by the errors package, which contains:

    if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) {
        return true
    }

The interface here is not a named type.
This commit is contained in:
Ayke van Laethem
2020-03-28 15:02:42 +01:00
committed by Ron Evans
parent cc4a4c755f
commit 0596b3c003
3 changed files with 14 additions and 5 deletions
+3
View File
@@ -26,6 +26,9 @@ func main() {
println("Stringer.String():", s.String())
var itf interface{} = s
println("Stringer.(*Thing).String():", itf.(Stringer).String())
if s, ok := s.(interface{ String() string }); ok {
println("s has String() method:", s.String())
}
println("nested switch:", nestedSwitch('v', 3))