cuelang.org/go@v0.10.1/cue/testdata/cycle/issue429.txtar (about)

     1  TODO: a bound value resolving to a disjunction should probably
     2  be an error. In this case #Size.amx should resolve.
     3  
     4  -- in.cue --
     5  // Range disjunction without cycle (checks only one-way).
     6  #Size: {
     7  	res: uint | *0
     8  	min: >res | *(1 + res)
     9  	max: >min | *min
    10  }
    11  
    12  s0: #Size & {res: 1}
    13  // This discards the default for max. This is correct, but unfortunate.
    14  // TODO: is there a tweak to the default mechanism possible that would fix that?
    15  //       Tread very carefully, though! Perhaps we could have a builtin that
    16  //       discards any default, so that we can at least manually override this
    17  //       behavior.
    18  s1: #Size & {min: 5}
    19  s2: #Size & {max: 5}
    20  s3: #Size & {
    21  	min: 5
    22  	max: 10
    23  }
    24  es3: #Size & {
    25  	min: 10
    26  	max: 5
    27  }
    28  
    29  // Disjunctions with cycles
    30  // TODO: improve error message here. Logic is correct, though.
    31  #nonEmptyRange: {
    32  	min: *1 | int
    33  	min: <max
    34  	max: >min
    35  }
    36  r1: #nonEmptyRange & {
    37  	min: 3
    38  }
    39  r2: #nonEmptyRange & {
    40  	max: 5
    41  }
    42  r3: #nonEmptyRange & {
    43  	min: 3
    44  	max: 6
    45  }
    46  
    47  er3: #nonEmptyRange & {
    48  	min: 5
    49  	max: 5
    50  }
    51  -- out/eval/stats --
    52  Leaks:  0
    53  Freed:  98
    54  Reused: 91
    55  Allocs: 7
    56  Retain: 12
    57  
    58  Unifications: 40
    59  Conjuncts:    150
    60  Disjuncts:    101
    61  -- out/evalalpha --
    62  Errors:
    63  es3.max: conflicting values 1 and 5:
    64      ./in.cue:4:16
    65      ./in.cue:22:7
    66  es3.max: conflicting values 10 and 5:
    67      ./in.cue:21:7
    68      ./in.cue:22:7
    69  es3.max: invalid value 5 (out of bound >10):
    70      ./in.cue:5:7
    71      ./in.cue:22:7
    72  er3.max: invalid value 5 (out of bound >5):
    73      ./in.cue:30:7
    74      ./in.cue:45:7
    75  
    76  Result:
    77  (_|_){
    78    // [eval]
    79    #Size: (#struct){
    80      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    81      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    82      max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
    83    }
    84    s0: (#struct){
    85      res: (int){ 1 }
    86      min: (number){ |(*(int){ 2 }, (number){ >1 }) }
    87      max: (number){ |(*(int){ 2 }, (number){ >1 }, (number){ >2 }) }
    88    }
    89    s1: (#struct){
    90      min: (int){ 5 }
    91      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    92      max: (number){ |((number){ >5 }, (int){ 5 }) }
    93    }
    94    s2: (#struct){
    95      max: (int){ 5 }
    96      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    97      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    98    }
    99    s3: (#struct){
   100      min: (int){ 5 }
   101      max: (int){ 10 }
   102      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   103    }
   104    es3: (_|_){
   105      // [eval]
   106      min: (int){ 10 }
   107      max: (_|_){
   108        // [eval] es3.max: conflicting values 1 and 5:
   109        //     ./in.cue:4:16
   110        //     ./in.cue:22:7
   111        // es3.max: conflicting values 10 and 5:
   112        //     ./in.cue:21:7
   113        //     ./in.cue:22:7
   114        // es3.max: invalid value 5 (out of bound >10):
   115        //     ./in.cue:5:7
   116        //     ./in.cue:22:7
   117      }
   118      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   119    }
   120    #nonEmptyRange: (#struct){
   121      min: (int){ |(*(int){ 1 }, (int){ int }) }
   122      max: (number){ >1 }
   123    }
   124    r1: (#struct){
   125      min: (int){ 3 }
   126      max: (number){ >3 }
   127    }
   128    r2: (#struct){
   129      max: (int){ 5 }
   130      min: (int){ |(*(int){ 1 }, (int){ &(<5, int) }) }
   131    }
   132    r3: (#struct){
   133      min: (int){ 3 }
   134      max: (int){ 6 }
   135    }
   136    er3: (_|_){
   137      // [eval]
   138      min: (int){ 5 }
   139      max: (_|_){
   140        // [eval] er3.max: invalid value 5 (out of bound >5):
   141        //     ./in.cue:30:7
   142        //     ./in.cue:45:7
   143      }
   144    }
   145  }
   146  -- diff/-out/evalalpha<==>+out/eval --
   147  diff old new
   148  --- old
   149  +++ new
   150  @@ -1,26 +1,16 @@
   151   Errors:
   152  -er3.min: 2 errors in empty disjunction:
   153  -er3.min: conflicting values 1 and 5:
   154  -    ./in.cue:28:8
   155  -    ./in.cue:43:6
   156  -    ./in.cue:44:7
   157  -es3.max: 3 errors in empty disjunction:
   158   es3.max: conflicting values 1 and 5:
   159       ./in.cue:4:16
   160  -    ./in.cue:5:15
   161  -    ./in.cue:20:6
   162       ./in.cue:22:7
   163   es3.max: conflicting values 10 and 5:
   164  -    ./in.cue:5:15
   165  -    ./in.cue:20:6
   166       ./in.cue:21:7
   167       ./in.cue:22:7
   168   es3.max: invalid value 5 (out of bound >10):
   169       ./in.cue:5:7
   170       ./in.cue:22:7
   171  -er3.min: invalid value 5 (out of bound <5):
   172  -    ./in.cue:29:7
   173  -    ./in.cue:44:7
   174  +er3.max: invalid value 5 (out of bound >5):
   175  +    ./in.cue:30:7
   176  +    ./in.cue:45:7
   177   
   178   Result:
   179   (_|_){
   180  @@ -36,34 +26,28 @@
   181       max: (number){ |(*(int){ 2 }, (number){ >1 }, (number){ >2 }) }
   182     }
   183     s1: (#struct){
   184  -    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   185  -    min: (int){ 5 }
   186  -    max: (number){ |(*(int){ 5 }, (number){ >5 }) }
   187  +    min: (int){ 5 }
   188  +    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   189  +    max: (number){ |((number){ >5 }, (int){ 5 }) }
   190     }
   191     s2: (#struct){
   192  -    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   193  -    min: (number){ |(*(int){ 1 }, (number){ >0 }) }
   194  -    max: (int){ 5 }
   195  +    max: (int){ 5 }
   196  +    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   197  +    min: (number){ |(*(int){ 1 }, (number){ >0 }) }
   198     }
   199     s3: (#struct){
   200  -    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   201       min: (int){ 5 }
   202       max: (int){ 10 }
   203  +    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   204     }
   205     es3: (_|_){
   206       // [eval]
   207  -    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   208       min: (int){ 10 }
   209       max: (_|_){
   210  -      // [eval] es3.max: 3 errors in empty disjunction:
   211  -      // es3.max: conflicting values 1 and 5:
   212  +      // [eval] es3.max: conflicting values 1 and 5:
   213         //     ./in.cue:4:16
   214  -      //     ./in.cue:5:15
   215  -      //     ./in.cue:20:6
   216         //     ./in.cue:22:7
   217         // es3.max: conflicting values 10 and 5:
   218  -      //     ./in.cue:5:15
   219  -      //     ./in.cue:20:6
   220         //     ./in.cue:21:7
   221         //     ./in.cue:22:7
   222         // es3.max: invalid value 5 (out of bound >10):
   223  @@ -70,11 +54,10 @@
   224         //     ./in.cue:5:7
   225         //     ./in.cue:22:7
   226       }
   227  +    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   228     }
   229     #nonEmptyRange: (#struct){
   230  -    min: (_|_){
   231  -      // [cycle] cycle error
   232  -    }
   233  +    min: (int){ |(*(int){ 1 }, (int){ int }) }
   234       max: (number){ >1 }
   235     }
   236     r1: (#struct){
   237  @@ -82,8 +65,8 @@
   238       max: (number){ >3 }
   239     }
   240     r2: (#struct){
   241  +    max: (int){ 5 }
   242       min: (int){ |(*(int){ 1 }, (int){ &(<5, int) }) }
   243  -    max: (int){ 5 }
   244     }
   245     r3: (#struct){
   246       min: (int){ 3 }
   247  @@ -91,25 +74,11 @@
   248     }
   249     er3: (_|_){
   250       // [eval]
   251  -    min: (_|_){
   252  -      // [eval] er3.min: 2 errors in empty disjunction:
   253  -      // er3.min: conflicting values 1 and 5:
   254  -      //     ./in.cue:28:8
   255  -      //     ./in.cue:43:6
   256  -      //     ./in.cue:44:7
   257  -      // er3.min: invalid value 5 (out of bound <5):
   258  -      //     ./in.cue:29:7
   259  -      //     ./in.cue:44:7
   260  -    }
   261  -    max: (_|_){
   262  -      // [eval] er3.min: 2 errors in empty disjunction:
   263  -      // er3.min: conflicting values 1 and 5:
   264  -      //     ./in.cue:28:8
   265  -      //     ./in.cue:43:6
   266  -      //     ./in.cue:44:7
   267  -      // er3.min: invalid value 5 (out of bound <5):
   268  -      //     ./in.cue:29:7
   269  -      //     ./in.cue:44:7
   270  +    min: (int){ 5 }
   271  +    max: (_|_){
   272  +      // [eval] er3.max: invalid value 5 (out of bound >5):
   273  +      //     ./in.cue:30:7
   274  +      //     ./in.cue:45:7
   275       }
   276     }
   277   }
   278  -- diff/todo/p2 --
   279  #nonEmptyRange: missing disjunction error, or at least missing validation.
   280  At least this seems more correct than the old evaluator. It is an
   281  incomplete error at best.
   282  -- diff/explanation --
   283  s1.max: the changes in default behavior as are shown here are according to spec,
   284  as is described in disjunctions/specdeviation.txtar. These changes may pose too
   285  much of a problem for the transition to the new evaluator, though.
   286  TODO: consider reintroducing bugs.
   287  -- diff/todo/p3 --
   288  Reordering.
   289  Missing empty disjunction message.
   290  Missing error positions.
   291  -- out/eval --
   292  Errors:
   293  er3.min: 2 errors in empty disjunction:
   294  er3.min: conflicting values 1 and 5:
   295      ./in.cue:28:8
   296      ./in.cue:43:6
   297      ./in.cue:44:7
   298  es3.max: 3 errors in empty disjunction:
   299  es3.max: conflicting values 1 and 5:
   300      ./in.cue:4:16
   301      ./in.cue:5:15
   302      ./in.cue:20:6
   303      ./in.cue:22:7
   304  es3.max: conflicting values 10 and 5:
   305      ./in.cue:5:15
   306      ./in.cue:20:6
   307      ./in.cue:21:7
   308      ./in.cue:22:7
   309  es3.max: invalid value 5 (out of bound >10):
   310      ./in.cue:5:7
   311      ./in.cue:22:7
   312  er3.min: invalid value 5 (out of bound <5):
   313      ./in.cue:29:7
   314      ./in.cue:44:7
   315  
   316  Result:
   317  (_|_){
   318    // [eval]
   319    #Size: (#struct){
   320      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   321      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
   322      max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
   323    }
   324    s0: (#struct){
   325      res: (int){ 1 }
   326      min: (number){ |(*(int){ 2 }, (number){ >1 }) }
   327      max: (number){ |(*(int){ 2 }, (number){ >1 }, (number){ >2 }) }
   328    }
   329    s1: (#struct){
   330      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   331      min: (int){ 5 }
   332      max: (number){ |(*(int){ 5 }, (number){ >5 }) }
   333    }
   334    s2: (#struct){
   335      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   336      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
   337      max: (int){ 5 }
   338    }
   339    s3: (#struct){
   340      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   341      min: (int){ 5 }
   342      max: (int){ 10 }
   343    }
   344    es3: (_|_){
   345      // [eval]
   346      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   347      min: (int){ 10 }
   348      max: (_|_){
   349        // [eval] es3.max: 3 errors in empty disjunction:
   350        // es3.max: conflicting values 1 and 5:
   351        //     ./in.cue:4:16
   352        //     ./in.cue:5:15
   353        //     ./in.cue:20:6
   354        //     ./in.cue:22:7
   355        // es3.max: conflicting values 10 and 5:
   356        //     ./in.cue:5:15
   357        //     ./in.cue:20:6
   358        //     ./in.cue:21:7
   359        //     ./in.cue:22:7
   360        // es3.max: invalid value 5 (out of bound >10):
   361        //     ./in.cue:5:7
   362        //     ./in.cue:22:7
   363      }
   364    }
   365    #nonEmptyRange: (#struct){
   366      min: (_|_){
   367        // [cycle] cycle error
   368      }
   369      max: (number){ >1 }
   370    }
   371    r1: (#struct){
   372      min: (int){ 3 }
   373      max: (number){ >3 }
   374    }
   375    r2: (#struct){
   376      min: (int){ |(*(int){ 1 }, (int){ &(<5, int) }) }
   377      max: (int){ 5 }
   378    }
   379    r3: (#struct){
   380      min: (int){ 3 }
   381      max: (int){ 6 }
   382    }
   383    er3: (_|_){
   384      // [eval]
   385      min: (_|_){
   386        // [eval] er3.min: 2 errors in empty disjunction:
   387        // er3.min: conflicting values 1 and 5:
   388        //     ./in.cue:28:8
   389        //     ./in.cue:43:6
   390        //     ./in.cue:44:7
   391        // er3.min: invalid value 5 (out of bound <5):
   392        //     ./in.cue:29:7
   393        //     ./in.cue:44:7
   394      }
   395      max: (_|_){
   396        // [eval] er3.min: 2 errors in empty disjunction:
   397        // er3.min: conflicting values 1 and 5:
   398        //     ./in.cue:28:8
   399        //     ./in.cue:43:6
   400        //     ./in.cue:44:7
   401        // er3.min: invalid value 5 (out of bound <5):
   402        //     ./in.cue:29:7
   403        //     ./in.cue:44:7
   404      }
   405    }
   406  }
   407  -- out/compile --
   408  --- in.cue
   409  {
   410    #Size: {
   411      res: (&(int, >=0)|*0)
   412      min: (>〈0;res〉|*(1 + 〈0;res〉))
   413      max: (>〈0;min〉|*〈0;min〉)
   414    }
   415    s0: (〈0;#Size〉 & {
   416      res: 1
   417    })
   418    s1: (〈0;#Size〉 & {
   419      min: 5
   420    })
   421    s2: (〈0;#Size〉 & {
   422      max: 5
   423    })
   424    s3: (〈0;#Size〉 & {
   425      min: 5
   426      max: 10
   427    })
   428    es3: (〈0;#Size〉 & {
   429      min: 10
   430      max: 5
   431    })
   432    #nonEmptyRange: {
   433      min: (*1|int)
   434      min: <〈0;max〉
   435      max: >〈0;min〉
   436    }
   437    r1: (〈0;#nonEmptyRange〉 & {
   438      min: 3
   439    })
   440    r2: (〈0;#nonEmptyRange〉 & {
   441      max: 5
   442    })
   443    r3: (〈0;#nonEmptyRange〉 & {
   444      min: 3
   445      max: 6
   446    })
   447    er3: (〈0;#nonEmptyRange〉 & {
   448      min: 5
   449      max: 5
   450    })
   451  }