...

Text file src/cuelang.org/go/cue/testdata/cycle/issue429.txtar

Documentation: cuelang.org/go/cue/testdata/cycle

     1TODO: a bound value resolving to a disjunction should probably
     2be 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
    12s0: #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.
    18s1: #Size & {min: 5}
    19s2: #Size & {max: 5}
    20s3: #Size & {
    21	min: 5
    22	max: 10
    23}
    24es3: #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}
    36r1: #nonEmptyRange & {
    37	min: 3
    38}
    39r2: #nonEmptyRange & {
    40	max: 5
    41}
    42r3: #nonEmptyRange & {
    43	min: 3
    44	max: 6
    45}
    46
    47er3: #nonEmptyRange & {
    48	min: 5
    49	max: 5
    50}
    51-- out/eval/stats --
    52Leaks:  0
    53Freed:  98
    54Reused: 91
    55Allocs: 7
    56Retain: 12
    57
    58Unifications: 40
    59Conjuncts:    150
    60Disjuncts:    101
    61-- out/eval --
    62Errors:
    63er3.min: 2 errors in empty disjunction:
    64er3.min: conflicting values 1 and 5:
    65    ./in.cue:28:8
    66    ./in.cue:43:6
    67    ./in.cue:44:7
    68es3.max: 3 errors in empty disjunction:
    69es3.max: conflicting values 1 and 5:
    70    ./in.cue:4:16
    71    ./in.cue:5:15
    72    ./in.cue:20:6
    73    ./in.cue:22:7
    74es3.max: conflicting values 10 and 5:
    75    ./in.cue:5:15
    76    ./in.cue:20:6
    77    ./in.cue:21:7
    78    ./in.cue:22:7
    79es3.max: invalid value 5 (out of bound >10):
    80    ./in.cue:5:7
    81    ./in.cue:22:7
    82er3.min: invalid value 5 (out of bound <5):
    83    ./in.cue:29:7
    84    ./in.cue:44:7
    85
    86Result:
    87(_|_){
    88  // [eval]
    89  #Size: (#struct){
    90    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    91    min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    92    max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
    93  }
    94  s0: (#struct){
    95    res: (int){ 1 }
    96    min: (number){ |(*(int){ 2 }, (number){ >1 }) }
    97    max: (number){ |(*(int){ 2 }, (number){ >1 }, (number){ >2 }) }
    98  }
    99  s1: (#struct){
   100    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   101    min: (int){ 5 }
   102    max: (number){ |(*(int){ 5 }, (number){ >5 }) }
   103  }
   104  s2: (#struct){
   105    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   106    min: (number){ |(*(int){ 1 }, (number){ >0 }) }
   107    max: (int){ 5 }
   108  }
   109  s3: (#struct){
   110    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   111    min: (int){ 5 }
   112    max: (int){ 10 }
   113  }
   114  es3: (_|_){
   115    // [eval]
   116    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
   117    min: (int){ 10 }
   118    max: (_|_){
   119      // [eval] es3.max: 3 errors in empty disjunction:
   120      // es3.max: conflicting values 1 and 5:
   121      //     ./in.cue:4:16
   122      //     ./in.cue:5:15
   123      //     ./in.cue:20:6
   124      //     ./in.cue:22:7
   125      // es3.max: conflicting values 10 and 5:
   126      //     ./in.cue:5:15
   127      //     ./in.cue:20:6
   128      //     ./in.cue:21:7
   129      //     ./in.cue:22:7
   130      // es3.max: invalid value 5 (out of bound >10):
   131      //     ./in.cue:5:7
   132      //     ./in.cue:22:7
   133    }
   134  }
   135  #nonEmptyRange: (#struct){
   136    min: (_|_){
   137      // [cycle] cycle error
   138    }
   139    max: (number){ >1 }
   140  }
   141  r1: (#struct){
   142    min: (int){ 3 }
   143    max: (number){ >3 }
   144  }
   145  r2: (#struct){
   146    min: (int){ |(*(int){ 1 }, (int){ &(<5, int) }) }
   147    max: (int){ 5 }
   148  }
   149  r3: (#struct){
   150    min: (int){ 3 }
   151    max: (int){ 6 }
   152  }
   153  er3: (_|_){
   154    // [eval]
   155    min: (_|_){
   156      // [eval] er3.min: 2 errors in empty disjunction:
   157      // er3.min: conflicting values 1 and 5:
   158      //     ./in.cue:28:8
   159      //     ./in.cue:43:6
   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:43:6
   170      //     ./in.cue:44:7
   171      // er3.min: invalid value 5 (out of bound <5):
   172      //     ./in.cue:29:7
   173      //     ./in.cue:44:7
   174    }
   175  }
   176}
   177-- out/compile --
   178--- in.cue
   179{
   180  #Size: {
   181    res: (&(int, >=0)|*0)
   182    min: (>〈0;res〉|*(1 + 〈0;res〉))
   183    max: (>〈0;min〉|*〈0;min〉)
   184  }
   185  s0: (〈0;#Size〉 & {
   186    res: 1
   187  })
   188  s1: (〈0;#Size〉 & {
   189    min: 5
   190  })
   191  s2: (〈0;#Size〉 & {
   192    max: 5
   193  })
   194  s3: (〈0;#Size〉 & {
   195    min: 5
   196    max: 10
   197  })
   198  es3: (〈0;#Size〉 & {
   199    min: 10
   200    max: 5
   201  })
   202  #nonEmptyRange: {
   203    min: (*1|int)
   204    min: <〈0;max〉
   205    max: >〈0;min〉
   206  }
   207  r1: (〈0;#nonEmptyRange〉 & {
   208    min: 3
   209  })
   210  r2: (〈0;#nonEmptyRange〉 & {
   211    max: 5
   212  })
   213  r3: (〈0;#nonEmptyRange〉 & {
   214    min: 3
   215    max: 6
   216  })
   217  er3: (〈0;#nonEmptyRange〉 & {
   218    min: 5
   219    max: 5
   220  })
   221}

View as plain text