99 "reflect"
1010 "sort"
1111 "sync"
12-
13- "github.com/sanity-io/litter"
1412)
1513
1614var (
@@ -252,7 +250,6 @@ func (s *state) assign(dst reflect.Value, value reflect.Value) (reflect.Value, e
252250 // TODO: deref the current pointer and use that instead
253251 if s .current .IsRoot () {
254252 _ , err := s .assignValue (dst , value )
255- fmt .Printf ("--------------\n ROOT\n \" %v\" => %v\n --------------\n " , t , dst .Type ())
256253 return dst , err
257254 }
258255
@@ -264,18 +261,29 @@ func (s *state) assign(dst reflect.Value, value reflect.Value) (reflect.Value, e
264261 // can i just overwrite src?
265262 var nd reflect.Value
266263 nd , err = s .resolveNext (dst , t )
267- fmt .Printf ("resolved: \" %v\" => %v\n " , t , nd .Type ())
268264 if err != nil {
269265 return nd , err
270266 }
271267
272268 shouldSet := false
269+ switch nd .Kind () {
270+ case reflect .Ptr :
271+ if nd .IsNil () {
272+ nd .Set (reflect .New (nd .Type ().Elem ()))
273+ }
274+ case reflect .Interface :
275+ if nd .IsNil () {
276+ return nd , newError (ErrUnreachable , * s , nd .Type ())
277+ }
278+ }
279+
273280 if ! nd .IsValid () {
274- switch dst .Kind () {
281+ switch dst .Elem (). Kind () {
275282 case reflect .Map , reflect .Slice :
276283 shouldSet = true
277284 nd = reflect .Zero (dst .Type ().Elem ())
278285 default :
286+ fmt .Println (dst .Type ())
279287 // TODO: figure out which other types would be invalid and remove this panic
280288 panic ("resolving an invalid value which is not an entry on a map/slice is not done" )
281289 }
@@ -291,41 +299,26 @@ func (s *state) assign(dst reflect.Value, value reflect.Value) (reflect.Value, e
291299 nd = pv
292300 }
293301
294- fmt .Printf ("new dst: \" %v\" => %v\n " , t , nd .Type ())
295- fmt .Printf ("cur dst: \" %v\" => %v\n " , t , dst .Type ())
296302 _ = shouldSet
303+
297304 var nv reflect.Value
298305 nv , err = s .assign (nd , value )
299-
300- fmt .Printf ("Prepending \" %v\" to \" %s\" \n " , s .current , t )
301306 s .current = s .current .Prepend (t )
302- fmt . Printf ( "new val: \" %v \" => %v \n " , t , nv . Type ())
307+
303308 if err != nil {
304309 return dst , err
305310 }
306-
307- fmt .Printf ("calling assignValue(%v, %v) with current = %v, token = %v\n " , nd .Type (), nv .Elem ().Type (), s .current , t )
308- fmt .Printf ("val: %v\n " , value .Type ())
309- fmt .Printf ("dst: %v\n " , dst .Type ())
310311 nd , err = s .assignValue (nd , nv .Elem ())
311312 if err != nil {
312313 return nd , err
313314 }
314-
315- fmt .Printf ("--------------\n \" %v\" => %v\n --------------\n " , t , nd .Type ())
316315 return dst , nil
317316}
318317
319318func (s * state ) assignValue (dst reflect.Value , v reflect.Value ) (reflect.Value , error ) {
320319 var err error
321320 cur := s .current
322- fmt .Println ("\n assignValue:" )
323- fmt .Printf ("current: \" %s\" " , cur )
324- fmt .Printf ("\n dst: %v" , dst .Elem ().Type ())
325- fmt .Printf ("\n value: %v\n \n " , v .Type ())
326- fmt .Printf ("---------------\n ASSIGN VALUE: " )
327- litter .Dump (v .Interface ())
328- fmt .Println ("---------------" )
321+
329322 if dst .Type ().Implements (typeAssigner ) {
330323 err = dst .Interface ().(Assigner ).AssignByJSONPointer (& cur , v )
331324 if err != nil {
0 commit comments