Skip to content

Commit fa3bf5f

Browse files
committed
cue: set DynamicLabel
For certain cases in the API the DynamicLabel needs to be explicitly set. Also, Template needs to recognize when Lookup can be applied for the new evaluator. Issue #3060 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Iad2a9ff913588ec3151ca61121aa714aa0b571f6 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194058 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 05640c2 commit fa3bf5f

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

cue/types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,8 +1817,12 @@ func (v hiddenValue) Template() func(label string) Value {
18171817
return nil
18181818
}
18191819

1820+
// Implementation for the old evaluator.
18201821
types := v.v.OptionalTypes()
1821-
if types&(adt.HasAdditional|adt.HasPattern) == 0 {
1822+
switch {
1823+
case types&(adt.HasAdditional|adt.HasPattern) != 0:
1824+
case v.v.PatternConstraints != nil:
1825+
default:
18221826
return nil
18231827
}
18241828

cue/types_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,8 @@ func TestTemplate(t *testing.T) {
18501850
value string
18511851
path []string
18521852
want string
1853+
1854+
skip bool
18531855
}{{
18541856
value: `
18551857
a: [Name=string]: Name
@@ -1881,10 +1883,14 @@ func TestTemplate(t *testing.T) {
18811883
`,
18821884
path: []string{"a", "foo", "b", ""},
18831885
want: `{"c":"foolabel","d":"label"}`,
1886+
1887+
skip: true, // TODO: reordering
18841888
}}
18851889
for _, tc := range testCases {
18861890
runMatrix(t, "", func(t *testing.T, cfg *evalConfig) {
1887-
TODO_V3(t, cfg)
1891+
if tc.skip {
1892+
TODO_V3(t, cfg)
1893+
}
18881894

18891895
v := cfg.getValue(t, tc.value)
18901896
for _, p := range tc.path {

internal/core/adt/composite.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,12 @@ func (v *Vertex) MatchAndInsert(ctx *OpContext, arc *Vertex) {
10311031
for _, pc := range pcs.Pairs {
10321032
if matchPattern(ctx, pc.Pattern, arc.Label) {
10331033
for _, c := range pc.Constraint.Conjuncts {
1034+
env := *(c.Env)
1035+
if arc.Label.Index() < MaxIndex {
1036+
env.DynamicLabel = arc.Label
1037+
}
1038+
c.Env = &env
1039+
10341040
root := arc.rootCloseContext(ctx)
10351041
root.insertConjunct(ctx, root, c, c.CloseInfo, ArcMember, true, false)
10361042
}

0 commit comments

Comments
 (0)