Skip to content

Commit 1d3a0df

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 7a2fb40 commit 1d3a0df

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/go/types/operand.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ func operandString(x *operand, qf Qualifier) string {
122122
case invalid, novalue, builtin, typexpr:
123123
// no type
124124
default:
125-
// has type
126-
if isUntyped(x.typ) {
127-
buf.WriteString(x.typ.(*Basic).name)
128-
buf.WriteByte(' ')
129-
break
125+
// should have a type, but be cautious (don't crash during printing)
126+
if x.typ != nil {
127+
if isUntyped(x.typ) {
128+
buf.WriteString(x.typ.(*Basic).name)
129+
buf.WriteByte(' ')
130+
break
131+
}
132+
hasType = true
130133
}
131-
hasType = true
132134
}
133135

134136
// <mode>

0 commit comments

Comments
 (0)