Skip to content

Commit c789d3e

Browse files
committed
internal/cmd/cue-ast-print: do not panic on invalid values
For example, in SliceExpr, the High field can be a nil interface, and that caused us to panic as reflect.Value.Elem returns a zero Value in such a scenario. Thanks to Rudolf Farkas for the report and fix. Note that we don't have any tests right now, as this tool is used only for debugging purposes. Closes #2771 as merged. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Id41797ea500b75bbc7a09f7f40cc9e51f5c0931a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194721 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 97695d0 commit c789d3e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

internal/cmd/cue-ast-print/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ func (d *debugPrinter) value(v reflect.Value) {
7575
if v.Kind() == reflect.Interface {
7676
v = v.Elem()
7777
}
78-
// We print the original pointer type if there was one.
79-
origType := v.Type()
80-
v = reflect.Indirect(v)
8178

79+
// Indirecting a nil interface/pointer gives a zero value;
80+
// stop as calling reflect.Value.Type on an invalid type would panic.
8281
if !v.IsValid() {
83-
// Indirecting a nil interface/pointer gives a zero value.
8482
d.printf("nil")
8583
return
8684
}
85+
// We print the original pointer type if there was one.
86+
origType := v.Type()
87+
v = reflect.Indirect(v)
88+
8789
t := v.Type()
8890
switch t {
8991
// Simple types which can stringify themselves.

0 commit comments

Comments
 (0)