From 1d3a0df4bb77af0158d25854c85ad87cc36fe8dc Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 21 Jun 2017 16:20:00 -0700 Subject: [PATCH] go/types: more robust operand printing 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/go/types/operand.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/go/types/operand.go b/src/go/types/operand.go index b2f16b64d8..07247bd6f5 100644 --- a/src/go/types/operand.go +++ b/src/go/types/operand.go @@ -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 } // -- 2.50.0