|
9 | 9 | "reflect" |
10 | 10 | "strconv" |
11 | 11 | "sync" |
| 12 | + |
| 13 | + "github.com/sanity-io/litter" |
12 | 14 | ) |
13 | 15 |
|
14 | 16 | var ( |
@@ -114,10 +116,6 @@ func (s *state) resolve(v reflect.Value) (reflect.Value, error) { |
114 | 116 | } |
115 | 117 |
|
116 | 118 | func (s *state) resolveNext(v reflect.Value, t Token) (reflect.Value, error) { |
117 | | - // fmt.Println("t", t) |
118 | | - // fmt.Println("nummethod", v.Type().NumMethod()) |
119 | | - // fmt.Println("caninterface", v.CanInterface()) |
120 | | - // fmt.Println("type", v.Type()) |
121 | 119 | if v.Type().NumMethod() > 0 && v.CanInterface() { |
122 | 120 | if resolver, ok := v.Interface().(Resolver); ok { |
123 | 121 | rv, err := s.resolveResolver(resolver, v, t) |
@@ -159,7 +157,7 @@ func (s *state) resolveResolver(r Resolver, rv reflect.Value, t Token) (reflect. |
159 | 157 | if err != nil { |
160 | 158 | // if the Resolver returns an error, it can either be a YieldOperation |
161 | 159 | // which continues the flow or an actual error. |
162 | | - if errors.Is(err, YieldOperation) { |
| 160 | + if !errors.Is(err, YieldOperation) { |
163 | 161 | return rv, newError(err, *s, reflect.TypeOf(rv)) |
164 | 162 | } |
165 | 163 | s.current = prev |
@@ -344,22 +342,30 @@ func (s *state) assign(dst reflect.Value, value reflect.Value) (reflect.Value, e |
344 | 342 | fmt.Println("nv.Elem.Type", nv.Elem().Type()) |
345 | 343 | fmt.Println("nv.Elem.IsNil", nv.IsNil()) |
346 | 344 | fmt.Println("dst.Type", dst.Type()) |
347 | | - |
348 | | - if dst.Type().Implements(typeAssigner) && !dst.IsNil() { |
349 | | - err = dst.Elem().Interface().(Assigner).AssignByJSONPointer(&cur, nv.Elem().Interface()) |
350 | | - if err != nil { |
351 | | - if !errors.Is(err, YieldOperation) { |
352 | | - return dst, newError(err, *s, dst.Elem().Type()) |
| 345 | + if dst.Type().NumMethod() > 0 && dst.CanInterface() { |
| 346 | + if assigner, ok := dst.Interface().(Assigner); ok { |
| 347 | + fmt.Println("dst.Elem().Type()", dst.Elem().Type()) |
| 348 | + fmt.Println("assigner", assigner) |
| 349 | + if assigner == nil { |
| 350 | + fmt.Println("wtf is assigner nil for?") |
| 351 | + } |
| 352 | + nve := nv.Elem().Interface() |
| 353 | + fmt.Println("nve:", litter.Sdump(nve)) |
| 354 | + assigner.AssignByJSONPointer(&cur, nve) |
| 355 | + if err != nil { |
| 356 | + if !errors.Is(err, YieldOperation) { |
| 357 | + return dst, newError(err, *s, dst.Elem().Type()) |
| 358 | + } else { |
| 359 | + // the Assigner has yielded operation back to jsonpointer |
| 360 | + // resetting current incase the Assigner mutated it |
| 361 | + cur = s.current |
| 362 | + } |
353 | 363 | } else { |
354 | | - // the Assigner has yielded operation back to jsonpointer |
355 | | - // resetting current incase the Assigner mutated it |
356 | | - cur = s.current |
| 364 | + return dst, nil |
357 | 365 | } |
358 | | - } else { |
359 | | - return dst, nil |
| 366 | + // updating state to reflect the new token if it was set by assigner |
| 367 | + s.current = cur |
360 | 368 | } |
361 | | - // updating state to reflect the new token if it was set by assigner |
362 | | - s.current = cur |
363 | 369 | } |
364 | 370 |
|
365 | 371 | nd, err = s.assignValue(nd, nv.Elem()) |
|
0 commit comments