...

Text file src/cuelang.org/go/cue/testdata/disjunctions/specdeviation.txtar

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

     1It turns out the semantics of the spec is somewhat awkward,
     2though theoretically nicer. It seems like we do need to change
     3the definition somewhat to make it less awkward, or at least
     4come up with a good workaround before adopting the spec.
     5
     6We have introduce a small hack to mimic the old behavior for scalar
     7values.
     8
     9Note that the value of p below is now 2 (default), but should
    10be the non-concrete 2 | int.
    11
    12Proof:
    13    p: *((*1 | int) & 2)  | int   // substitution of both P conjuncts in p
    14    p: *(*_|_ | 2)  | int         // U1: distribute conjuncts
    15    p: *_|_ | 2  | int            // M2: remove mark
    16    p: 2  | int                   // value after removing default.
    17
    18-- in.cue --
    19Q: *1 | int
    20q: *Q | int // 1 as expected
    21
    22P: *1 | int
    23P: 2
    24p: *P | int // now 2, but should be (2 | int), according to the spec:
    25
    26// Here the inner default may not be used as it is masked by the outer default.
    27r: (*3 | (*1 | 2)) & (1 | 2)
    28
    29// Here the inner default is used, as there are no defaults marked in the
    30// outer disjunction.
    31s: (3 | (*1 | 2)) & (1 | 2)
    32
    33s1: #Size & {min: 5}
    34
    35#Size: {
    36	max: >min | *min
    37	res: uint | *0
    38	min: >res | *(1 + res)
    39}
    40
    41staged: {
    42	c: ("a" | "b") & (*(*"a" | string) | string)
    43	d: (*(*"a" | string) | string) & ("a" | "b")
    44}
    45
    46issue763a: {
    47	#A: {
    48		v: "a" | "b" | "c" // change to string to fix
    49	}
    50
    51	h: [string]: #A
    52
    53	h: [=~"^b"]: #A & {
    54		v: *h.a.v | string
    55	}
    56
    57	h: a: {
    58		v: *"a" | string
    59	}
    60
    61	h: baa: _
    62	h: boo: _
    63}
    64-- out/eval/stats --
    65Leaks:  0
    66Freed:  171
    67Reused: 158
    68Allocs: 13
    69Retain: 2
    70
    71Unifications: 28
    72Conjuncts:    217
    73Disjuncts:    172
    74-- out/eval --
    75(struct){
    76  Q: (int){ |(*(int){ 1 }, (int){ int }) }
    77  q: (int){ |(*(int){ 1 }, (int){ int }) }
    78  P: (int){ 2 }
    79  p: (int){ |(*(int){ 2 }, (int){ int }) }
    80  r: (int){ |((int){ 1 }, (int){ 2 }) }
    81  s: (int){ |(*(int){ 1 }, (int){ 2 }) }
    82  s1: (#struct){
    83    max: (number){ |(*(int){ 5 }, (number){ >5 }) }
    84    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    85    min: (int){ 5 }
    86  }
    87  #Size: (#struct){
    88    max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
    89    res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    90    min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    91  }
    92  staged: (struct){
    93    c: (string){ |(*(string){ "a" }, (string){ "b" }) }
    94    d: (string){ |(*(string){ "a" }, (string){ "b" }) }
    95  }
    96  issue763a: (struct){
    97    #A: (#struct){
    98      v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) }
    99    }
   100    h: (struct){
   101      a: (#struct){
   102        v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
   103      }
   104      baa: (#struct){
   105        v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
   106      }
   107      boo: (#struct){
   108        v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
   109      }
   110    }
   111  }
   112}
   113-- out/compile --
   114--- in.cue
   115{
   116  Q: (*1|int)
   117  q: (*〈0;Q〉|int)
   118  P: (*1|int)
   119  P: 2
   120  p: (*〈0;P〉|int)
   121  r: ((*3|(*1|2)) & (1|2))
   122  s: ((3|(*1|2)) & (1|2))
   123  s1: (〈0;#Size〉 & {
   124    min: 5
   125  })
   126  #Size: {
   127    max: (>〈0;min〉|*〈0;min〉)
   128    res: (&(int, >=0)|*0)
   129    min: (>〈0;res〉|*(1 + 〈0;res〉))
   130  }
   131  staged: {
   132    c: (("a"|"b") & (*(*"a"|string)|string))
   133    d: ((*(*"a"|string)|string) & ("a"|"b"))
   134  }
   135  issue763a: {
   136    #A: {
   137      v: ("a"|"b"|"c")
   138    }
   139    h: {
   140      [string]: 〈1;#A〉
   141    }
   142    h: {
   143      [=~"^b"]: (〈1;#A〉 & {
   144        v: (*〈2;h〉.a.v|string)
   145      })
   146    }
   147    h: {
   148      a: {
   149        v: (*"a"|string)
   150      }
   151    }
   152    h: {
   153      baa: _
   154    }
   155    h: {
   156      boo: _
   157    }
   158  }
   159}

View as plain text