diff --git a/pkg/yqlib/operator_alternative.go b/pkg/yqlib/operator_alternative.go index 39d084ca..ca6ba2d7 100644 --- a/pkg/yqlib/operator_alternative.go +++ b/pkg/yqlib/operator_alternative.go @@ -9,6 +9,9 @@ func alternativeFunc(d *dataTreeNavigator, context Context, lhs *CandidateNode, if lhs == nil { return rhs, nil } + if rhs == nil { + return lhs, nil + } lhs.Node = unwrapDoc(lhs.Node) rhs.Node = unwrapDoc(rhs.Node) log.Debugf("Alternative LHS: %v", lhs.Node.Tag) diff --git a/pkg/yqlib/operator_alternative_test.go b/pkg/yqlib/operator_alternative_test.go index 9a57a052..f4a986c4 100644 --- a/pkg/yqlib/operator_alternative_test.go +++ b/pkg/yqlib/operator_alternative_test.go @@ -19,6 +19,14 @@ var alternativeOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::a: bridge\n", }, }, + { + skipDoc: true, + expression: `.a // .b`, + document: `a: 2`, + expected: []string{ + "D0, P[a], (!!int)::2\n", + }, + }, { description: "LHS is defined", expression: `.a // "hello"`,