Skip to content

Commit 0aec29c

Browse files
committed
fixed build issue
1 parent 3c83b2e commit 0aec29c

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

datamodel/high/node_builder.go

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -176,50 +176,52 @@ func (n *NodeBuilder) add(key string, i int) {
176176
nodeEntry.Value = f
177177
}
178178

179-
// if there is no low level object, then we cannot extract line numbers,
179+
// if there is no low-level object, then we cannot extract line numbers,
180180
// so skip and default to 0, which means a new entry to the spec.
181181
// this will place new content and the top of the rendered object.
182182
if n.Low != nil && !reflect.ValueOf(n.Low).IsZero() {
183183
lowFieldValue := reflect.ValueOf(n.Low).Elem().FieldByName(key)
184-
fLow := lowFieldValue.Interface()
185-
value = reflect.ValueOf(fLow)
186-
187-
nodeEntry.LowValue = fLow
188-
switch value.Kind() {
189-
190-
case reflect.Slice:
191-
l := value.Len()
192-
lines := make([]int, l)
193-
for g := 0; g < l; g++ {
194-
qw := value.Index(g).Interface()
195-
if we, wok := qw.(low.HasKeyNode); wok {
196-
lines[g] = we.GetKeyNode().Line
197-
}
198-
}
199-
sort.Slice(lines, func(i, j int) bool {
200-
return lines[i] < lines[j]
201-
})
202-
if len(lines) > 0 {
203-
nodeEntry.Line = lines[0]
204-
}
205-
case reflect.Struct:
206-
y := value.Interface()
207-
nodeEntry.Line = 9999 + i
208-
if nb, ok := y.(low.HasValueNodeUntyped); ok {
209-
if nb.IsReference() {
210-
if jk, kj := y.(low.HasKeyNode); kj {
211-
nodeEntry.Line = jk.GetKeyNode().Line
212-
break
184+
if lowFieldValue.IsValid() {
185+
fLow := lowFieldValue.Interface()
186+
value = reflect.ValueOf(fLow)
187+
188+
nodeEntry.LowValue = fLow
189+
switch value.Kind() {
190+
191+
case reflect.Slice:
192+
l := value.Len()
193+
lines := make([]int, l)
194+
for g := 0; g < l; g++ {
195+
qw := value.Index(g).Interface()
196+
if we, wok := qw.(low.HasKeyNode); wok {
197+
lines[g] = we.GetKeyNode().Line
213198
}
214199
}
215-
if nb.GetValueNode() != nil {
216-
nodeEntry.Line = nb.GetValueNode().Line
200+
sort.Slice(lines, func(i, j int) bool {
201+
return lines[i] < lines[j]
202+
})
203+
if len(lines) > 0 {
204+
nodeEntry.Line = lines[0]
205+
}
206+
case reflect.Struct:
207+
y := value.Interface()
208+
nodeEntry.Line = 9999 + i
209+
if nb, ok := y.(low.HasValueNodeUntyped); ok {
210+
if nb.IsReference() {
211+
if jk, kj := y.(low.HasKeyNode); kj {
212+
nodeEntry.Line = jk.GetKeyNode().Line
213+
break
214+
}
215+
}
216+
if nb.GetValueNode() != nil {
217+
nodeEntry.Line = nb.GetValueNode().Line
218+
}
217219
}
220+
default:
221+
// everything else, weight it to the bottom of the rendered object.
222+
// this is things that we have no way of knowing where they should be placed.
223+
nodeEntry.Line = 9999 + i
218224
}
219-
default:
220-
// everything else, weight it to the bottom of the rendered object.
221-
// this is things that we have no way of knowing where they should be placed.
222-
nodeEntry.Line = 9999 + i
223225
}
224226
}
225227
if nodeEntry.Value != nil {

datamodel/high/node_builder_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ type test1 struct {
8585
Thunk valueReferenceStruct `yaml:"thunk,omitempty"`
8686
Thrim *valueReferenceStruct `yaml:"thrim,omitempty"`
8787
Thril *orderedmap.Map[string, *valueReferenceStruct] `yaml:"thril,omitempty"`
88-
Thryp string `yaml:"description"`
8988
Extensions *orderedmap.Map[string, *yaml.Node] `yaml:"-"`
9089
ignoreMe string `yaml:"-"`
9190
IgnoreMe string `yaml:"-"`
@@ -1143,8 +1142,10 @@ func TestNewNodeBuilder_Int64_Negative(t *testing.T) {
11431142
}
11441143

11451144
func TestNewNodeBuilder_DescriptionOmitEmpty(t *testing.T) {
1146-
t1 := test1{
1147-
Thryp: "",
1145+
t1 := struct {
1146+
Blah string `yaml:"description"`
1147+
}{
1148+
Blah: "",
11481149
}
11491150

11501151
nb := NewNodeBuilder(&t1, &t1)

0 commit comments

Comments
 (0)