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