Skip to content

Commit 777c977

Browse files
authored
Cue: Detect references with unifications (#1065)
1 parent c0eb3b7 commit 777c977

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

internal/jennies/golang/templates/types/disjunction_of_refs.json_unmarshal.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{{- $json := importStdPkg "encoding/json" -}}
2-
{{- $errors := importStdPkg "errors" -}}
32
{{- $struct := .def.Type.Struct -}}
43
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode `{{ .def.Name|formatObjectName }}` from JSON.
54
func (resource *{{ .def.Name|formatObjectName }}) UnmarshalJSON(raw []byte) error {

internal/simplecue/generator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ func getReference(v cue.Value) (bool, cue.Value, cue.Value) {
446446
if op == cue.AndOp && exprs[0].Subsume(exprs[1]) == nil && exprs[1].Subsume(exprs[0]) == nil {
447447
return true, exprs[0], exprs[1]
448448
}
449+
450+
// We could have a reference unified with a cue.TopKind (_). We can assume that if we have an existing path unified with this
451+
// it's a valid reference.
452+
if path.String() != "" && exprs[1].IncompleteKind() == cue.TopKind {
453+
return true, exprs[0], exprs[0]
454+
}
455+
449456
return false, v, v
450457
}
451458

0 commit comments

Comments
 (0)