rootStep constructs the first path step. If x and y have differing types, then they are stored within an empty interface type.
(x, y interface{})
| 139 | // rootStep constructs the first path step. If x and y have differing types, |
| 140 | // then they are stored within an empty interface type. |
| 141 | func rootStep(x, y interface{}) PathStep { |
| 142 | vx := reflect.ValueOf(x) |
| 143 | vy := reflect.ValueOf(y) |
| 144 | |
| 145 | // If the inputs are different types, auto-wrap them in an empty interface |
| 146 | // so that they have the same parent type. |
| 147 | var t reflect.Type |
| 148 | if !vx.IsValid() || !vy.IsValid() || vx.Type() != vy.Type() { |
| 149 | t = anyType |
| 150 | if vx.IsValid() { |
| 151 | vvx := reflect.New(t).Elem() |
| 152 | vvx.Set(vx) |
| 153 | vx = vvx |
| 154 | } |
| 155 | if vy.IsValid() { |
| 156 | vvy := reflect.New(t).Elem() |
| 157 | vvy.Set(vy) |
| 158 | vy = vvy |
| 159 | } |
| 160 | } else { |
| 161 | t = vx.Type() |
| 162 | } |
| 163 | |
| 164 | return &pathStep{t, vx, vy} |
| 165 | } |
| 166 | |
| 167 | type state struct { |
| 168 | // These fields represent the "comparison state". |