cuelang.org/go@v0.13.0/cue/testdata/cycle/disjunction.txtar (about)

     1  -- in.cue --
     2  // cycle is a structural cycle
     3  cycle: a: cycle
     4  
     5  // reference to outside structural cycle
     6  r1a: cycle | int
     7  r1b: int | cycle
     8  
     9  r2a: cycle | 1
    10  r2b: 1 | cycle
    11  
    12  r3a: cycle | null
    13  r3b: null | cycle
    14  
    15  r4a: cycle | {}
    16  r4b: {} | cycle
    17  
    18  r5a: cycle | []
    19  r5b: [] | cycle
    20  
    21  // reference to ancestor node
    22  s1a: x: s1a | int
    23  s1b: x: int | s1b
    24  
    25  s2a: x: s2a | 1
    26  s2b: x: 1 | s2b
    27  
    28  s3a: x: s3a | null
    29  s3b: x: null | s3b
    30  
    31  s4a: x: s4a | {}
    32  s4b: x: {} | s4b
    33  
    34  s5a: x: s5a | []
    35  s5b: x: [] | s5b
    36  
    37  -- issue3042.cue --
    38  issue3042: {
    39  	// Recursively, any field named "name" should begin with "foo".
    40  	// The data value below should then fail.
    41  	#foo: =~"^foo"
    42  	#nesting: string | {name?: #foo, [string]: #nesting} | [...#nesting]
    43  
    44  	data: #nesting & {
    45  		secret: {
    46  			infra: [
    47  				{name: "bar1"}
    48  			]
    49  		}
    50  	}
    51  }
    52  -- out/eval/stats --
    53  Leaks:  0
    54  Freed:  199
    55  Reused: 181
    56  Allocs: 18
    57  Retain: 0
    58  
    59  Unifications: 93
    60  Conjuncts:    280
    61  Disjuncts:    199
    62  -- out/eval --
    63  Errors:
    64  cycle.a: structural cycle
    65  
    66  Result:
    67  (_|_){
    68    // [structural cycle]
    69    cycle: (_|_){
    70      // [structural cycle]
    71      a: (_|_){
    72        // [structural cycle] cycle.a: structural cycle
    73      }
    74    }
    75    r1a: (int){ int }
    76    r1b: (int){ int }
    77    r2a: (int){ 1 }
    78    r2b: (int){ 1 }
    79    r3a: (null){ null }
    80    r3b: (null){ null }
    81    r4a: (struct){
    82    }
    83    r4b: (struct){
    84    }
    85    r5a: (#list){
    86    }
    87    r5b: (#list){
    88    }
    89    s1a: (struct){
    90      x: (int){ int }
    91    }
    92    s1b: (struct){
    93      x: (int){ int }
    94    }
    95    s2a: (struct){
    96      x: (int){ 1 }
    97    }
    98    s2b: (struct){
    99      x: (int){ 1 }
   100    }
   101    s3a: (struct){
   102      x: (null){ null }
   103    }
   104    s3b: (struct){
   105      x: (null){ null }
   106    }
   107    s4a: (struct){
   108      x: (struct){
   109      }
   110    }
   111    s4b: (struct){
   112      x: (struct){
   113      }
   114    }
   115    s5a: (struct){
   116      x: (#list){
   117      }
   118    }
   119    s5b: (struct){
   120      x: (#list){
   121      }
   122    }
   123    issue3042: (struct){
   124      #foo: (string){ =~"^foo" }
   125      #nesting: ((string|list|struct)){ |((string){ string }, (#struct){
   126          name?: (string){ =~"^foo" }
   127        }, (list){
   128        }) }
   129      data: (#struct){
   130        secret: (#struct){
   131          infra: (#list){
   132            0: (struct){
   133              name: (string){ "bar1" }
   134            }
   135          }
   136          name?: (string){ =~"^foo" }
   137        }
   138        name?: (string){ =~"^foo" }
   139      }
   140    }
   141  }
   142  -- out/evalalpha --
   143  Errors:
   144  cycle.a: structural cycle
   145  issue3042.data: 2 errors in empty disjunction:
   146  issue3042.data: conflicting values [...#nesting] and {secret:{infra:[{name:"bar1"}]}} (mismatched types list and struct):
   147      ./issue3042.cue:5:57
   148      ./issue3042.cue:7:19
   149  issue3042.data: conflicting values string and {secret:{infra:[{name:"bar1"}]}} (mismatched types string and struct):
   150      ./issue3042.cue:5:12
   151      ./issue3042.cue:7:19
   152  
   153  Result:
   154  (_|_){
   155    // [eval]
   156    cycle: (_|_){
   157      // [structural cycle]
   158      a: (_|_){
   159        // [structural cycle] cycle.a: structural cycle
   160      }
   161    }
   162    r1a: (int){ int }
   163    r1b: (int){ int }
   164    r2a: (int){ 1 }
   165    r2b: (int){ 1 }
   166    r3a: (null){ null }
   167    r3b: (null){ null }
   168    r4a: (struct){
   169    }
   170    r4b: (struct){
   171    }
   172    r5a: (#list){
   173    }
   174    r5b: (#list){
   175    }
   176    s1a: (struct){
   177      x: (int){ int }
   178    }
   179    s1b: (struct){
   180      x: (int){ int }
   181    }
   182    s2a: (struct){
   183      x: (int){ 1 }
   184    }
   185    s2b: (struct){
   186      x: (int){ 1 }
   187    }
   188    s3a: (struct){
   189      x: (null){ null }
   190    }
   191    s3b: (struct){
   192      x: (null){ null }
   193    }
   194    s4a: (struct){
   195      x: (struct){
   196      }
   197    }
   198    s4b: (struct){
   199      x: (struct){
   200      }
   201    }
   202    s5a: (struct){
   203      x: (#list){
   204      }
   205    }
   206    s5b: (struct){
   207      x: (#list){
   208      }
   209    }
   210    issue3042: (_|_){
   211      // [eval]
   212      #foo: (string){ =~"^foo" }
   213      #nesting: ((string|list|struct)){ |((string){ string }, (#struct){
   214          name?: (string){ =~"^foo" }
   215        }, (list){
   216        }) }
   217      data: (_|_){
   218        // [eval] issue3042.data: 2 errors in empty disjunction:
   219        // issue3042.data: conflicting values [...#nesting] and {secret:{infra:[{name:"bar1"}]}} (mismatched types list and struct):
   220        //     ./issue3042.cue:5:57
   221        //     ./issue3042.cue:7:19
   222        // issue3042.data: conflicting values string and {secret:{infra:[{name:"bar1"}]}} (mismatched types string and struct):
   223        //     ./issue3042.cue:5:12
   224        //     ./issue3042.cue:7:19
   225        secret: (struct){
   226          infra: (list){ list }
   227        }
   228      }
   229    }
   230  }
   231  -- diff/-out/evalalpha<==>+out/eval --
   232  diff old new
   233  --- old
   234  +++ new
   235  @@ -1,9 +1,16 @@
   236   Errors:
   237   cycle.a: structural cycle
   238  +issue3042.data: 2 errors in empty disjunction:
   239  +issue3042.data: conflicting values [...#nesting] and {secret:{infra:[{name:"bar1"}]}} (mismatched types list and struct):
   240  +    ./issue3042.cue:5:57
   241  +    ./issue3042.cue:7:19
   242  +issue3042.data: conflicting values string and {secret:{infra:[{name:"bar1"}]}} (mismatched types string and struct):
   243  +    ./issue3042.cue:5:12
   244  +    ./issue3042.cue:7:19
   245   
   246   Result:
   247   (_|_){
   248  -  // [structural cycle]
   249  +  // [eval]
   250     cycle: (_|_){
   251       // [structural cycle]
   252       a: (_|_){
   253  @@ -58,22 +65,24 @@
   254       x: (#list){
   255       }
   256     }
   257  -  issue3042: (struct){
   258  +  issue3042: (_|_){
   259  +    // [eval]
   260       #foo: (string){ =~"^foo" }
   261       #nesting: ((string|list|struct)){ |((string){ string }, (#struct){
   262           name?: (string){ =~"^foo" }
   263         }, (list){
   264         }) }
   265  -    data: (#struct){
   266  -      secret: (#struct){
   267  -        infra: (#list){
   268  -          0: (struct){
   269  -            name: (string){ "bar1" }
   270  -          }
   271  -        }
   272  -        name?: (string){ =~"^foo" }
   273  +    data: (_|_){
   274  +      // [eval] issue3042.data: 2 errors in empty disjunction:
   275  +      // issue3042.data: conflicting values [...#nesting] and {secret:{infra:[{name:"bar1"}]}} (mismatched types list and struct):
   276  +      //     ./issue3042.cue:5:57
   277  +      //     ./issue3042.cue:7:19
   278  +      // issue3042.data: conflicting values string and {secret:{infra:[{name:"bar1"}]}} (mismatched types string and struct):
   279  +      //     ./issue3042.cue:5:12
   280  +      //     ./issue3042.cue:7:19
   281  +      secret: (struct){
   282  +        infra: (list){ list }
   283         }
   284  -      name?: (string){ =~"^foo" }
   285       }
   286     }
   287   }
   288  -- diff/explanation --
   289  issue3042: The old evaluator incorrectly resolved to a concrete value,
   290  whereas the new evaluator correctly spots that data.secret.infra.name does not unify with #foo.
   291  The new closedness of evalv3 may hide such errors by reporting a spurious
   292  "field not allowed" error.
   293  -- out/compile --
   294  --- in.cue
   295  {
   296    cycle: {
   297      a: 〈1;cycle〉
   298    }
   299    r1a: (〈0;cycle〉|int)
   300    r1b: (int|〈0;cycle〉)
   301    r2a: (〈0;cycle〉|1)
   302    r2b: (1|〈0;cycle〉)
   303    r3a: (〈0;cycle〉|null)
   304    r3b: (null|〈0;cycle〉)
   305    r4a: (〈0;cycle〉|{})
   306    r4b: ({}|〈0;cycle〉)
   307    r5a: (〈0;cycle〉|[])
   308    r5b: ([]|〈0;cycle〉)
   309    s1a: {
   310      x: (〈1;s1a〉|int)
   311    }
   312    s1b: {
   313      x: (int|〈1;s1b〉)
   314    }
   315    s2a: {
   316      x: (〈1;s2a〉|1)
   317    }
   318    s2b: {
   319      x: (1|〈1;s2b〉)
   320    }
   321    s3a: {
   322      x: (〈1;s3a〉|null)
   323    }
   324    s3b: {
   325      x: (null|〈1;s3b〉)
   326    }
   327    s4a: {
   328      x: (〈1;s4a〉|{})
   329    }
   330    s4b: {
   331      x: ({}|〈1;s4b〉)
   332    }
   333    s5a: {
   334      x: (〈1;s5a〉|[])
   335    }
   336    s5b: {
   337      x: ([]|〈1;s5b〉)
   338    }
   339  }
   340  --- issue3042.cue
   341  {
   342    issue3042: {
   343      #foo: =~"^foo"
   344      #nesting: (string|{
   345        name?: 〈1;#foo〉
   346        [string]: 〈1;#nesting〉
   347      }|[
   348        ...〈1;#nesting〉,
   349      ])
   350      data: (〈0;#nesting〉 & {
   351        secret: {
   352          infra: [
   353            {
   354              name: "bar1"
   355            },
   356          ]
   357        }
   358      })
   359    }
   360  }