From a5258013e36965d4dc1d610653f256f4f20e24cb Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Thu, 22 Aug 2024 16:05:59 +0200 Subject: [PATCH] internal/core/adt: add tests for referencing required fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is in anticipation for a slight change in semantics. Signed-off-by: Marcel van Lohuizen Change-Id: I500464546a2da016ae155b20b6980bf02e682e70 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199897 Reviewed-by: Daniel Martí TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine --- cue/testdata/eval/required.txtar | 284 ++++++++++++++++++++++++++++++- 1 file changed, 277 insertions(+), 7 deletions(-) diff --git a/cue/testdata/eval/required.txtar b/cue/testdata/eval/required.txtar index b6423f9aa03..49c471929a5 100644 --- a/cue/testdata/eval/required.txtar +++ b/cue/testdata/eval/required.txtar @@ -37,6 +37,44 @@ allowed: issue2306: { #B: b!: int } + +reference: { + toWithinDefinition: p1:{ + #Foo: a!: int + b: #Foo.a + } + toWithinDefinition: p2:{ + b: #Foo.a + #Foo: a!: int + } + toFieldFromDefinition: p1: { + #Foo: a!: int + b: #Foo + c: b.a + } + toFieldFromDefinition: p2: { + c: b.a + b: #Foo + #Foo: a!: int + } + toNonDefinition: p1: { + x: y!: _ + b: x.y + } + toNonDefinition: p2: { + b: x.y + x: y!: _ + } + toConcrete: p1: { + a!: 1 + b: a + 1 + } + toConcrete: p2: { + b: a + 1 + a!: 1 + } +} + -- out/compile -- --- in.cue { @@ -99,17 +137,81 @@ allowed: issue2306: { } } } + reference: { + toWithinDefinition: { + p1: { + #Foo: { + a!: int + } + b: 〈0;#Foo〉.a + } + } + toWithinDefinition: { + p2: { + b: 〈0;#Foo〉.a + #Foo: { + a!: int + } + } + } + toFieldFromDefinition: { + p1: { + #Foo: { + a!: int + } + b: 〈0;#Foo〉 + c: 〈0;b〉.a + } + } + toFieldFromDefinition: { + p2: { + c: 〈0;b〉.a + b: 〈0;#Foo〉 + #Foo: { + a!: int + } + } + } + toNonDefinition: { + p1: { + x: { + y!: _ + } + b: 〈0;x〉.y + } + } + toNonDefinition: { + p2: { + b: 〈0;x〉.y + x: { + y!: _ + } + } + } + toConcrete: { + p1: { + a!: 1 + b: (〈0;a〉 + 1) + } + } + toConcrete: { + p2: { + b: (〈0;a〉 + 1) + a!: 1 + } + } + } } -- out/eval/stats -- Leaks: 0 -Freed: 27 -Reused: 21 -Allocs: 6 -Retain: 1 +Freed: 66 +Reused: 58 +Allocs: 8 +Retain: 13 -Unifications: 27 -Conjuncts: 40 -Disjuncts: 28 +Unifications: 66 +Conjuncts: 92 +Disjuncts: 79 -- out/evalalpha -- (_|_){ // [eval] @@ -161,6 +263,90 @@ Disjuncts: 28 } } } + reference: (struct){ + toWithinDefinition: (struct){ + p1: (struct){ + #Foo: (#struct){ + a!: (int){ int } + } + b: (_|_){ + // [incomplete] reference.toWithinDefinition.p1.b: cannot reference optional field: a: + // ./in.cue:43:11 + } + } + p2: (struct){ + b: (_|_){ + // [incomplete] reference.toWithinDefinition.p2.b: cannot reference optional field: a: + // ./in.cue:46:11 + } + #Foo: (#struct){ + a!: (int){ int } + } + } + } + toFieldFromDefinition: (struct){ + p1: (struct){ + #Foo: (#struct){ + a!: (int){ int } + } + b: (#struct){ + a!: (int){ int } + } + c: (_|_){ + // [incomplete] reference.toFieldFromDefinition.p1.c: cannot reference optional field: a: + // ./in.cue:52:8 + } + } + p2: (struct){ + c: (_|_){ + // [incomplete] reference.toFieldFromDefinition.p2.c: cannot reference optional field: a: + // ./in.cue:55:8 + } + b: (#struct){ + a!: (int){ int } + } + #Foo: (#struct){ + a!: (int){ int } + } + } + } + toNonDefinition: (struct){ + p1: (struct){ + x: (struct){ + y!: (_){ _ } + } + b: (_|_){ + // [incomplete] reference.toNonDefinition.p1.b: cannot reference optional field: y: + // ./in.cue:61:8 + } + } + p2: (struct){ + b: (_|_){ + // [incomplete] reference.toNonDefinition.p2.b: cannot reference optional field: y: + // ./in.cue:64:8 + } + x: (struct){ + y!: (_){ _ } + } + } + } + toConcrete: (struct){ + p1: (struct){ + a!: (int){ 1 } + b: (_|_){ + // [incomplete] reference.toConcrete.p1.b: cannot reference optional field: a: + // ./in.cue:69:6 + } + } + p2: (struct){ + b: (_|_){ + // [incomplete] reference.toConcrete.p2.b: cannot reference optional field: a: + // ./in.cue:72:6 + } + a!: (int){ 1 } + } + } + } } -- diff/-out/evalalpha<==>+out/eval -- diff old new @@ -230,4 +416,88 @@ Missing position. } } } + reference: (struct){ + toWithinDefinition: (struct){ + p1: (struct){ + #Foo: (#struct){ + a!: (int){ int } + } + b: (_|_){ + // [incomplete] reference.toWithinDefinition.p1.b: cannot reference optional field: a: + // ./in.cue:43:11 + } + } + p2: (struct){ + b: (_|_){ + // [incomplete] reference.toWithinDefinition.p2.b: cannot reference optional field: a: + // ./in.cue:46:11 + } + #Foo: (#struct){ + a!: (int){ int } + } + } + } + toFieldFromDefinition: (struct){ + p1: (struct){ + #Foo: (#struct){ + a!: (int){ int } + } + b: (#struct){ + a!: (int){ int } + } + c: (_|_){ + // [incomplete] reference.toFieldFromDefinition.p1.c: cannot reference optional field: a: + // ./in.cue:52:8 + } + } + p2: (struct){ + c: (_|_){ + // [incomplete] reference.toFieldFromDefinition.p2.c: cannot reference optional field: a: + // ./in.cue:55:8 + } + b: (#struct){ + a!: (int){ int } + } + #Foo: (#struct){ + a!: (int){ int } + } + } + } + toNonDefinition: (struct){ + p1: (struct){ + x: (struct){ + y!: (_){ _ } + } + b: (_|_){ + // [incomplete] reference.toNonDefinition.p1.b: cannot reference optional field: y: + // ./in.cue:61:8 + } + } + p2: (struct){ + b: (_|_){ + // [incomplete] reference.toNonDefinition.p2.b: cannot reference optional field: y: + // ./in.cue:64:8 + } + x: (struct){ + y!: (_){ _ } + } + } + } + toConcrete: (struct){ + p1: (struct){ + a!: (int){ 1 } + b: (_|_){ + // [incomplete] reference.toConcrete.p1.b: cannot reference optional field: a: + // ./in.cue:69:6 + } + } + p2: (struct){ + b: (_|_){ + // [incomplete] reference.toConcrete.p2.b: cannot reference optional field: a: + // ./in.cue:72:6 + } + a!: (int){ 1 } + } + } + } }