]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: more robust operand printing
authorRobert Griesemer <gri@golang.org>
Wed, 21 Jun 2017 23:20:00 +0000 (16:20 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 22 Jun 2017 03:53:04 +0000 (03:53 +0000)
Not a fix but useful for further debugging, and safe.

For #18643.

Change-Id: I5fb4f4a8662007a26e945fff3986347855f00eab
Reviewed-on: https://go-review.googlesource.com/46393
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/go/types/operand.go

index b2f16b64d804242e9caeedea99aff77f7bd10cd9..07247bd6f58831a3f4ba3b4854a6de2e644bc21d 100644 (file)
@@ -122,13 +122,15 @@ func operandString(x *operand, qf Qualifier) string {
        case invalid, novalue, builtin, typexpr:
                // no type
        default:
-               // has type
-               if isUntyped(x.typ) {
-                       buf.WriteString(x.typ.(*Basic).name)
-                       buf.WriteByte(' ')
-                       break
+               // should have a type, but be cautious (don't crash during printing)
+               if x.typ != nil {
+                       if isUntyped(x.typ) {
+                               buf.WriteString(x.typ.(*Basic).name)
+                               buf.WriteByte(' ')
+                               break
+                       }
+                       hasType = true
                }
-               hasType = true
        }
 
        // <mode>