this repo has no description
0
fork

Configure Feed

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

cue: don't extract embedded values

Only non-value expressions are extracted.

Change-Id: Iecbcc66036cea68acf0679ef1a6d9a647bba4672
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9861
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>

+24 -6
+14 -6
cue/types.go
··· 2392 2392 ctx := v.ctx() 2393 2393 for _, d := range x.Decls { 2394 2394 switch x := d.(type) { 2395 + default: 2396 + fields = append(fields, d) 2397 + case adt.Value: 2398 + fields = append(fields, d) 2395 2399 case adt.Expr: 2396 2400 // embedding 2397 2401 n := &adt.Vertex{Label: v.v.Label} ··· 2400 2404 n.Finalize(ctx) 2401 2405 n.Parent = v.v.Parent 2402 2406 a = append(a, makeValue(v.idx, n, v.parent_)) 2403 - 2404 - default: 2405 - fields = append(fields, d) 2406 2407 } 2407 2408 } 2408 2409 if len(a) == 0 { ··· 2414 2415 n := &adt.Vertex{ 2415 2416 Label: v.v.Label, 2416 2417 } 2417 - c := adt.MakeRootConjunct(env, &adt.StructLit{ 2418 - Decls: fields, 2419 - }) 2418 + s := &adt.StructLit{} 2419 + if k := v.v.Kind(); k != adt.StructKind && k != BottomKind { 2420 + // TODO: we should also add such a declaration for embeddings 2421 + // of structs with definitions. However, this is currently 2422 + // also not supported at the CUE level. If we do, it may be 2423 + // best handled with a special mode of unification. 2424 + s.Decls = append(s.Decls, &adt.BasicType{K: k}) 2425 + } 2426 + s.Decls = append(s.Decls, fields...) 2427 + c := adt.MakeRootConjunct(env, s) 2420 2428 n.AddConjunct(c) 2421 2429 n.Finalize(ctx) 2422 2430 n.Parent = v.v.Parent
+10
cue/types_test.go
··· 3331 3331 input: `v: "Hello, \(x)! Welcome to \(place)", place: string, x: string`, 3332 3332 want: `\()("Hello, " .(〈〉 "x") "! Welcome to " .(〈〉 "place") "")`, 3333 3333 }, { 3334 + // Split out the reference, but ensure the split-off outer struct 3335 + // remains valid. 3336 + input: `v: { a, #b: 1 }, a: 2`, 3337 + want: `&(.(〈〉 "a") {int,#b:1})`, 3338 + }, { 3339 + // Result is an error, no need to split off. 3334 3340 input: `v: { a, b: 1 }, a: 2`, 3335 3341 want: `&(.(〈〉 "a") {b:1})`, 3342 + }, { 3343 + // Don't split of concrete values. 3344 + input: `v: { "foo", #def: 1 }`, 3345 + want: `{"foo",#def:1}`, 3336 3346 }, { 3337 3347 input: `v: { {c: a}, b: a }, a: int`, 3338 3348 want: `&({c:a} {b:a})`,