@@ -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 {
0 commit comments