this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue: remove long-deprecated and hidden Instance methods

Lookup, LookupDef, LookupField, and Fill were deprecated and hidden
between 2020 and 2021, and have remained in place since.

Given that these are not just hidden and deprecated,
but also methods on the itself deprecated Instance type,
it's time to remove them.

Just three usages of Lookup remained in our code; rewrite them.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ife1290a53a57762216ac7b480a69f1596342534d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1236071
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+8 -73
+3 -3
cmd/cue/cmd/custom.go
··· 61 61 // and adds them as cobra subcommands to cmd. 62 62 // The func is only used in `cue help cmd`, which doesn't show errors. 63 63 func addCustomCommands(c *Command, cmd *cobra.Command, typ string, tools *cue.Instance) { 64 - commands := tools.Lookup(typ) 64 + commands := tools.Value().LookupPath(cue.MakePath(cue.Str(typ))) 65 65 if !commands.Exists() { 66 66 return 67 67 } ··· 84 84 } 85 85 86 86 // TODO: validate allowing incomplete. 87 - cmds := tools.Lookup(typ) 88 - o := cmds.Lookup(name) 87 + cmds := tools.Value().LookupPath(cue.MakePath(cue.Str(typ))) 88 + o := cmds.LookupPath(cue.MakePath(cue.Str(name))) 89 89 if !o.Exists() { 90 90 return nil, o.Err() 91 91 }
-69
cue/instance.go
··· 221 221 222 222 return i 223 223 } 224 - 225 - // Lookup reports the value at a path starting from the top level struct. The 226 - // Exists method of the returned value will report false if the path did not 227 - // exist. The Err method reports if any error occurred during evaluation. The 228 - // empty path returns the top-level configuration struct. Use LookupDef for definitions or LookupField for 229 - // any kind of field. 230 - // 231 - // Deprecated: use [Value.LookupPath] 232 - func (inst *hiddenInstance) Lookup(path ...string) Value { 233 - return inst.Value().Lookup(path...) 234 - } 235 - 236 - // LookupDef reports the definition with the given name within struct v. The 237 - // Exists method of the returned value will report false if the definition did 238 - // not exist. The Err method reports if any error occurred during evaluation. 239 - // 240 - // Deprecated: use [Value.LookupPath] 241 - func (inst *hiddenInstance) LookupDef(path string) Value { 242 - return inst.Value().LookupDef(path) 243 - } 244 - 245 - // LookupField reports a Field at a path starting from v, or an error if the 246 - // path is not. The empty path returns v itself. 247 - // 248 - // It cannot look up hidden or unexported fields. 249 - // 250 - // Deprecated: use [Value.LookupPath] 251 - func (inst *hiddenInstance) LookupField(path ...string) (f FieldInfo, err error) { 252 - v := inst.Value() 253 - for _, k := range path { 254 - s, err := v.Struct() 255 - if err != nil { 256 - return f, err 257 - } 258 - 259 - f, err = s.FieldByName(k, true) 260 - if err != nil { 261 - return f, err 262 - } 263 - if f.IsHidden { 264 - return f, errNotFound 265 - } 266 - v = f.Value 267 - } 268 - return f, err 269 - } 270 - 271 - // Fill creates a new instance with the values of the old instance unified with 272 - // the given value. It is not possible to update the emit value. 273 - // 274 - // Values may be any Go value that can be converted to CUE, an ast.Expr or 275 - // a Value. In the latter case, it will panic if the Value is not from the same 276 - // Runtime. 277 - // 278 - // Deprecated: use [Value.FillPath] 279 - func (inst *hiddenInstance) Fill(x interface{}, path ...string) (*Instance, error) { 280 - v := inst.Value().Fill(x, path...) 281 - 282 - inst = addInst(inst.index, &Instance{ 283 - root: v.v, 284 - inst: nil, 285 - 286 - // Omit ImportPath to indicate this is not an importable package. 287 - Dir: inst.Dir, 288 - PkgName: inst.PkgName, 289 - Incomplete: inst.Incomplete, 290 - }) 291 - return inst, nil 292 - }
+5 -1
cue/types_test.go
··· 3559 3559 if tc.alt != "" { 3560 3560 want = tc.alt 3561 3561 } 3562 - v := fmt.Sprint(inst.Lookup(a...)) 3562 + sels := make([]cue.Selector, len(a)) 3563 + for i, p := range a { 3564 + sels[i] = cue.Str(p) 3565 + } 3566 + v := fmt.Sprint(inst.Value().LookupPath(cue.MakePath(sels...))) 3563 3567 if v != want { 3564 3568 t.Errorf("path resolved to %s; want %s", v, want) 3565 3569 }