github.com/solo-io/cue@v0.4.7/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  
    52  
    53  -- out/eval --
    54  Errors:
    55  er3.min: 2 errors in empty disjunction:
    56  er3.min: conflicting values 1 and 5:
    57      ./in.cue:28:11
    58      ./in.cue:43:6
    59      ./in.cue:44:10
    60  es3.max: 3 errors in empty disjunction:
    61  es3.max: conflicting values 1 and 5:
    62      ./in.cue:4:19
    63      ./in.cue:5:18
    64      ./in.cue:20:6
    65      ./in.cue:22:10
    66  es3.max: conflicting values 10 and 5:
    67      ./in.cue:5:18
    68      ./in.cue:20:6
    69      ./in.cue:21:10
    70      ./in.cue:22:10
    71  es3.max: invalid value 5 (out of bound >10):
    72      ./in.cue:5:10
    73      ./in.cue:22:10
    74  er3.max: invalid value 5 (out of bound >5):
    75      ./in.cue:30:10
    76      ./in.cue:45:10
    77  
    78  Result:
    79  (_|_){
    80    // [eval]
    81    #Size: (#struct){
    82      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    83      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    84      max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
    85    }
    86    s0: (#struct){
    87      res: (int){ 1 }
    88      min: (number){ |(*(int){ 2 }, (number){ >1 }) }
    89      max: (number){ |(*(int){ 2 }, (number){ >1 }, (number){ >2 }) }
    90    }
    91    s1: (#struct){
    92      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    93      min: (int){ 5 }
    94      max: (number){ |(*(int){ 5 }, (number){ >5 }) }
    95    }
    96    s2: (#struct){
    97      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    98      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    99      max: (int){ 5 }
   100    }
   101    s3: (#struct){
   102      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   103      min: (int){ 5 }
   104      max: (int){ 10 }
   105    }
   106    es3: (_|_){
   107      // [eval]
   108      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   109      min: (int){ 10 }
   110      max: (_|_){
   111        // [eval] es3.max: 3 errors in empty disjunction:
   112        // es3.max: conflicting values 1 and 5:
   113        //     ./in.cue:4:19
   114        //     ./in.cue:5:18
   115        //     ./in.cue:20:6
   116        //     ./in.cue:22:10
   117        // es3.max: conflicting values 10 and 5:
   118        //     ./in.cue:5:18
   119        //     ./in.cue:20:6
   120        //     ./in.cue:21:10
   121        //     ./in.cue:22:10
   122        // es3.max: invalid value 5 (out of bound >10):
   123        //     ./in.cue:5:10
   124        //     ./in.cue:22:10
   125      }
   126    }
   127    #nonEmptyRange: (#struct){
   128      min: (_|_){
   129        // [incomplete] #nonEmptyRange.min: incomplete cause disjunction
   130      }
   131      max: (_|_){
   132        // [incomplete] #nonEmptyRange.min: incomplete cause disjunction
   133      }
   134    }
   135    r1: (#struct){
   136      min: (int){ 3 }
   137      max: (number){ >3 }
   138    }
   139    r2: (#struct){
   140      min: (int){ |(*(int){ 1 }, (int){ &(<5, int) }) }
   141      max: (int){ 5 }
   142    }
   143    r3: (#struct){
   144      min: (int){ 3 }
   145      max: (int){ 6 }
   146    }
   147    er3: (_|_){
   148      // [eval]
   149      min: (_|_){
   150        // [eval] er3.min: 2 errors in empty disjunction:
   151        // er3.min: conflicting values 1 and 5:
   152        //     ./in.cue:28:11
   153        //     ./in.cue:43:6
   154        //     ./in.cue:44:10
   155        // er3.max: invalid value 5 (out of bound >5):
   156        //     ./in.cue:30:10
   157        //     ./in.cue:45:10
   158      }
   159      max: (_|_){
   160        // [eval] er3.max: invalid value 5 (out of bound >5):
   161        //     ./in.cue:30:10
   162        //     ./in.cue:45:10
   163      }
   164    }
   165  }
   166  -- out/compile --
   167  --- in.cue
   168  {
   169    #Size: {
   170      res: (&(int, >=0)|*0)
   171      min: (>〈0;res〉|*(1 + 〈0;res〉))
   172      max: (>〈0;min〉|*〈0;min〉)
   173    }
   174    s0: (〈0;#Size〉 & {
   175      res: 1
   176    })
   177    s1: (〈0;#Size〉 & {
   178      min: 5
   179    })
   180    s2: (〈0;#Size〉 & {
   181      max: 5
   182    })
   183    s3: (〈0;#Size〉 & {
   184      min: 5
   185      max: 10
   186    })
   187    es3: (〈0;#Size〉 & {
   188      min: 10
   189      max: 5
   190    })
   191    #nonEmptyRange: {
   192      min: (*1|int)
   193      min: <〈0;max〉
   194      max: >〈0;min〉
   195    }
   196    r1: (〈0;#nonEmptyRange〉 & {
   197      min: 3
   198    })
   199    r2: (〈0;#nonEmptyRange〉 & {
   200      max: 5
   201    })
   202    r3: (〈0;#nonEmptyRange〉 & {
   203      min: 3
   204      max: 6
   205    })
   206    er3: (〈0;#nonEmptyRange〉 & {
   207      min: 5
   208      max: 5
   209    })
   210  }