From 57af726d8fd7550ee341eddac6f04170fb2bcfd6 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Thu, 19 Dec 2024 17:14:34 +0100 Subject: [PATCH] internal/core/adt: add tests for issue 3415 Issue #3415 Signed-off-by: Marcel van Lohuizen Change-Id: I9bbc5e850aa437c1040987b056a88c99b33e9368 Dispatch-Trailer: {"type":"trybot","CL":1206122,"patchset":1,"ref":"refs/changes/22/1206122/1","targetBranch":"master"} --- cue/testdata/disjunctions/embed.txtar | 148 ++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 7 deletions(-) diff --git a/cue/testdata/disjunctions/embed.txtar b/cue/testdata/disjunctions/embed.txtar index ae55c0e5c..396399226 100644 --- a/cue/testdata/disjunctions/embed.txtar +++ b/cue/testdata/disjunctions/embed.txtar @@ -60,16 +60,38 @@ nested: { a: 1 | 2 | *( (3 | 4 | *( 5 | 6 | *7)) & ( 3 | 4 | ( *7 | 8 ))) } +-- issue3415.cue -- +issue3415: full: { + A: #A & { + i: { + _a + _b + _a: 1 + _b: 10 + } + } + + #A: { + i: *0 | number + } +} +issue3415: reduced: { + a: { + 1 + #b + #b: 10 + } + a: *0 | number +} + -- out/eval/stats -- -Leaks: 1 -Freed: 416 -Reused: 381 +Leaks: 19 +Freed: 430 +Reused: 413 Allocs: 36 -Retain: 1 +Retain: 5 -Unifications: 257 -Conjuncts: 478 -Disjuncts: 417 +Unifications: 268 +Conjuncts: 502 +Disjuncts: 438 -- out/evalalpha -- (struct){ default: (struct){ @@ -233,6 +255,33 @@ Disjuncts: 417 nested: (struct){ a: (int){ |(*(int){ 7 }, (int){ 2 }, (int){ 3 }, (int){ 4 }, (int){ 1 }) } } + issue3415: (struct){ + full: (struct){ + A: (#struct){ + i: (number){ |(*(int){ + 0 + _a: (int){ 1 } + _b: (int){ 10 } + }, (number){ + number + _a: (int){ 1 } + _b: (int){ 10 } + }) } + } + #A: (#struct){ + i: (number){ |(*(int){ 0 }, (number){ number }) } + } + } + reduced: (struct){ + a: (number){ |(*(int){ + 0 + #b: (int){ 10 } + }, (number){ + number + #b: (int){ 10 } + }) } + } + } } -- diff/-out/evalalpha<==>+out/eval -- diff old new @@ -256,6 +305,45 @@ diff old new a: (string){ "foo" } e: (string){ "bar" } }, (#struct){ +@@ -163,11 +163,15 @@ + issue3415: (struct){ + full: (struct){ + A: (#struct){ +- i: (int){ +- 11 +- _a: (int){ 1 } +- _b: (int){ 10 } +- } ++ i: (number){ |(*(int){ ++ 0 ++ _a: (int){ 1 } ++ _b: (int){ 10 } ++ }, (number){ ++ number ++ _a: (int){ 1 } ++ _b: (int){ 10 } ++ }) } + } + #A: (#struct){ + i: (number){ |(*(int){ 0 }, (number){ number }) } +@@ -174,10 +178,13 @@ + } + } + reduced: (struct){ +- a: (int){ +- 11 +- #b: (int){ 10 } +- } ++ a: (number){ |(*(int){ ++ 0 ++ #b: (int){ 10 } ++ }, (number){ ++ number ++ #b: (int){ 10 } ++ }) } + } + } + } -- diff/explanation -- The old algorithm was incorrect: the default value should not be carried: only {b: string} of the first disjunction can be part of the result. As it @@ -424,6 +512,26 @@ default either. nested: (struct){ a: (int){ |(*(int){ 7 }, (int){ 2 }, (int){ 3 }, (int){ 4 }, (int){ 1 }) } } + issue3415: (struct){ + full: (struct){ + A: (#struct){ + i: (int){ + 11 + _a: (int){ 1 } + _b: (int){ 10 } + } + } + #A: (#struct){ + i: (number){ |(*(int){ 0 }, (number){ number }) } + } + } + reduced: (struct){ + a: (int){ + 11 + #b: (int){ 10 } + } + } + } } -- out/compile -- --- in.cue @@ -515,3 +623,29 @@ default either. a: (1|2|*((3|4|*(5|6|*7)) & (3|4|(*7|8)))) } } +--- issue3415.cue +{ + issue3415: { + full: { + A: (〈0;#A〉 & { + i: { + (〈0;_a〉 + 〈0;_b〉) + _a: 1 + _b: 10 + } + }) + #A: { + i: (*0|number) + } + } + } + issue3415: { + reduced: { + a: { + (1 + 〈0;#b〉) + #b: 10 + } + a: (*0|number) + } + } +}