github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/disjunctions/specdeviation.txtar (about)

     1  It turns out the semantics of the spec is somewhat awkward,
     2  though theoretically nicer. It seems like we do need to change
     3  the definition somewhat to make it less awkward, or at least
     4  come up with a good workaround before adopting the spec.
     5  
     6  We have introduce a small hack to mimic the old behavior for scalar
     7  values.
     8  
     9  Note that the value of p below is now 2 (default), but should
    10  be the non-concrete 2 | int.
    11  
    12  Proof:
    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 --
    19  Q: *1 | int
    20  q: *Q | int // 1 as expected
    21  
    22  P: *1 | int
    23  P: 2
    24  p: *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.
    27  r: (*3 | (*1 | 2)) & (1 | 2)
    28  
    29  // Here the inner default is used, as there are no defaults marked in the
    30  // outer disjunction.
    31  s: (3 | (*1 | 2)) & (1 | 2)
    32  
    33  s1: #Size & {min: 5}
    34  
    35  #Size: {
    36  	max: >min | *min
    37  	res: uint | *0
    38  	min: >res | *(1 + res)
    39  }
    40  
    41  staged: {
    42  	c: ("a" | "b") & (*(*"a" | string) | string)
    43  	d: (*(*"a" | string) | string) & ("a" | "b")
    44  }
    45  
    46  issue763a: {
    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 --
    65  (struct){
    66    Q: (int){ |(*(int){ 1 }, (int){ int }) }
    67    q: (int){ |(*(int){ 1 }, (int){ int }) }
    68    P: (int){ 2 }
    69    p: (int){ |(*(int){ 2 }, (int){ int }) }
    70    r: (int){ |((int){ 1 }, (int){ 2 }) }
    71    s: (int){ |(*(int){ 1 }, (int){ 2 }) }
    72    s1: (#struct){
    73      max: (number){ |(*(int){ 5 }, (number){ >5 }) }
    74      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    75      min: (int){ 5 }
    76    }
    77    #Size: (#struct){
    78      max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
    79      res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
    80      min: (number){ |(*(int){ 1 }, (number){ >0 }) }
    81    }
    82    staged: (struct){
    83      c: (string){ |(*(string){ "a" }, (string){ "b" }) }
    84      d: (string){ |(*(string){ "a" }, (string){ "b" }) }
    85    }
    86    issue763a: (struct){
    87      #A: (#struct){
    88        v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) }
    89      }
    90      h: (struct){
    91        a: (#struct){
    92          v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
    93        }
    94        baa: (#struct){
    95          v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
    96        }
    97        boo: (#struct){
    98          v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
    99        }
   100      }
   101    }
   102  }
   103  -- out/compile --
   104  --- in.cue
   105  {
   106    Q: (*1|int)
   107    q: (*〈0;Q〉|int)
   108    P: (*1|int)
   109    P: 2
   110    p: (*〈0;P〉|int)
   111    r: ((*3|(*1|2)) & (1|2))
   112    s: ((3|(*1|2)) & (1|2))
   113    s1: (〈0;#Size〉 & {
   114      min: 5
   115    })
   116    #Size: {
   117      max: (>〈0;min〉|*〈0;min〉)
   118      res: (&(int, >=0)|*0)
   119      min: (>〈0;res〉|*(1 + 〈0;res〉))
   120    }
   121    staged: {
   122      c: (("a"|"b") & (*(*"a"|string)|string))
   123      d: ((*(*"a"|string)|string) & ("a"|"b"))
   124    }
   125    issue763a: {
   126      #A: {
   127        v: ("a"|"b"|"c")
   128      }
   129      h: {
   130        [string]: 〈1;#A〉
   131      }
   132      h: {
   133        [=~"^b"]: (〈1;#A〉 & {
   134          v: (*〈2;h〉.a.v|string)
   135        })
   136      }
   137      h: {
   138        a: {
   139          v: (*"a"|string)
   140        }
   141      }
   142      h: {
   143        baa: _
   144      }
   145      h: {
   146        boo: _
   147      }
   148    }
   149  }