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

     1  -- in.cue --
     2  a:  *1 | int
     3  aa: *1 | *2 | int
     4  
     5  b: {
     6  	name: "int"
     7  	val:  int
     8  } | {
     9  	name: "str"
    10  	val:  string
    11  }
    12  
    13  d: b & {val:  3}
    14  c: b & {name: "int", val: 3}
    15  e: b & {val:  "foo"}
    16  f: b & {name: "str", val: 3}
    17  
    18  // Disjunct elimination based on type.
    19  e1: {
    20  	a: null | {bar: 2}
    21  	b: (a & {}).bar
    22  }
    23  
    24  d1: {
    25  	a: (null | {c:      1}) & {}
    26  	b: {} & (null | {c: 1})
    27  }
    28  
    29  d2: {
    30  	a: ([...] | {c:      1}) & {}
    31  	b: {} & ([...] | {c: 1})
    32  }
    33  
    34  d3: {
    35  	a: (string | {c:      1}) & {}
    36  	b: {} & (string | {c: 1})
    37  }
    38  
    39  d4: {
    40  	a: (string | {c:      1}) & {}
    41  	b: {} & (string | {c: 1})
    42  }
    43  
    44  d5: {
    45  	a: (number | {c:      1}) & {}
    46  	b: {} & (number | {c: 1})
    47  }
    48  
    49  d6: {
    50  	a: (int | {c:      1}) & {}
    51  	b: {} & (int | {c: 1})
    52  }
    53  
    54  t10: {
    55  	schema: test
    56  	schema: string | {name: string}
    57  	#A: {string | {name: string}}
    58  
    59  	test: name: "Test"
    60  	test: #A
    61  }
    62  
    63  t10: {
    64  	schema: string | {name: string}
    65  	schema: test
    66  	#A: {string | {name: string}}
    67  
    68  	test: name: "Test"
    69  	test: #A
    70  }
    71  
    72  t10: {
    73  	#A: {string | {name: string}}
    74  
    75  	test: name: "Test"
    76  	test: #A
    77  
    78  	schema: string | {name: string}
    79  	schema: test
    80  }
    81  
    82  t11: {
    83  	a: #A
    84  	a: b
    85  
    86  	b:  #A & ["b"]
    87  	#A: ["a" | "b"] | {}
    88  }
    89  
    90  t11: {
    91  	b:  #A & ["b"]
    92  	#A: ["a" | "b"] | {}
    93  
    94  	a: b
    95  	a: #A
    96  }
    97  
    98  cross: {
    99  	a: *"word" | string
   100  	a: string | *"word"
   101  }
   102  
   103  d100: {
   104  	// Should we allow a selector to imply a struct or list? Would be convenient.
   105  	// This would be a spec change. Disallow for now.
   106  	i: null | {bar: 2}
   107  	j: i.bar
   108  }
   109  
   110  issue641: {
   111  	#A: {
   112  		type: "a"
   113  		x:    ""
   114  	}
   115  
   116  	#B: {
   117  		type: "b"
   118  		x:    string
   119  	}
   120  
   121  	#C: {
   122  		b: #A | #B
   123  	}
   124  
   125  	e: [string]: #C & {
   126  		b: #A | #B
   127  	}
   128  
   129  	e: foobar: #C & {
   130  		b: #B & {
   131  			x: "foobar"
   132  		}
   133  	}
   134  }
   135  -- out/eval --
   136  Errors:
   137  f: 2 errors in empty disjunction:
   138  f.name: conflicting values "int" and "str":
   139      ./in.cue:5:8
   140      ./in.cue:15:4
   141      ./in.cue:15:15
   142  f.val: conflicting values 3 and string (mismatched types int and string):
   143      ./in.cue:9:8
   144      ./in.cue:15:4
   145      ./in.cue:15:27
   146  
   147  Result:
   148  (_|_){
   149    // [eval]
   150    a: (int){ |(*(int){ 1 }, (int){ int }) }
   151    aa: (int){ |(*(int){ 1 }, *(int){ 2 }, (int){ int }) }
   152    b: (struct){ |((struct){
   153        name: (string){ "int" }
   154        val: (int){ int }
   155      }, (struct){
   156        name: (string){ "str" }
   157        val: (string){ string }
   158      }) }
   159    d: (struct){
   160      val: (int){ 3 }
   161      name: (string){ "int" }
   162    }
   163    c: (struct){
   164      name: (string){ "int" }
   165      val: (int){ 3 }
   166    }
   167    e: (struct){
   168      val: (string){ "foo" }
   169      name: (string){ "str" }
   170    }
   171    f: (_|_){
   172      // [eval] f: 2 errors in empty disjunction:
   173      // f.name: conflicting values "int" and "str":
   174      //     ./in.cue:5:8
   175      //     ./in.cue:15:4
   176      //     ./in.cue:15:15
   177      // f.val: conflicting values 3 and string (mismatched types int and string):
   178      //     ./in.cue:9:8
   179      //     ./in.cue:15:4
   180      //     ./in.cue:15:27
   181      name: (string){ "str" }
   182      val: (_|_){
   183        // [eval] f.val: conflicting values 3 and string (mismatched types int and string):
   184        //     ./in.cue:9:8
   185        //     ./in.cue:15:4
   186        //     ./in.cue:15:27
   187      }
   188    }
   189    e1: (struct){
   190      a: ((null|struct)){ |((null){ null }, (struct){
   191          bar: (int){ 2 }
   192        }) }
   193      b: (int){ 2 }
   194    }
   195    d1: (struct){
   196      a: (struct){
   197        c: (int){ 1 }
   198      }
   199      b: (struct){
   200        c: (int){ 1 }
   201      }
   202    }
   203    d2: (struct){
   204      a: (struct){
   205        c: (int){ 1 }
   206      }
   207      b: (struct){
   208        c: (int){ 1 }
   209      }
   210    }
   211    d3: (struct){
   212      a: (struct){
   213        c: (int){ 1 }
   214      }
   215      b: (struct){
   216        c: (int){ 1 }
   217      }
   218    }
   219    d4: (struct){
   220      a: (struct){
   221        c: (int){ 1 }
   222      }
   223      b: (struct){
   224        c: (int){ 1 }
   225      }
   226    }
   227    d5: (struct){
   228      a: (struct){
   229        c: (int){ 1 }
   230      }
   231      b: (struct){
   232        c: (int){ 1 }
   233      }
   234    }
   235    d6: (struct){
   236      a: (struct){
   237        c: (int){ 1 }
   238      }
   239      b: (struct){
   240        c: (int){ 1 }
   241      }
   242    }
   243    t10: (struct){
   244      schema: (#struct){
   245        name: (string){ "Test" }
   246      }
   247      #A: ((string|struct)){ |((string){ string }, (#struct){
   248          name: (string){ string }
   249        }) }
   250      test: (#struct){
   251        name: (string){ "Test" }
   252      }
   253    }
   254    t11: (struct){
   255      a: (#list){
   256        0: (string){ "b" }
   257      }
   258      b: (#list){
   259        0: (string){ "b" }
   260      }
   261      #A: ((list|struct)){ |((#list){
   262          0: (string){ |((string){ "a" }, (string){ "b" }) }
   263        }, (#struct){
   264        }) }
   265    }
   266    cross: (struct){
   267      a: (string){ |(*(string){ "word" }, (string){ string }) }
   268    }
   269    d100: (struct){
   270      i: ((null|struct)){ |((null){ null }, (struct){
   271          bar: (int){ 2 }
   272        }) }
   273      j: (_|_){
   274        // [incomplete] d100.j: unresolved disjunction null | {bar:2} (type (null|struct)):
   275        //     ./in.cue:106:5
   276      }
   277    }
   278    issue641: (struct){
   279      #A: (#struct){
   280        type: (string){ "a" }
   281        x: (string){ "" }
   282      }
   283      #B: (#struct){
   284        type: (string){ "b" }
   285        x: (string){ string }
   286      }
   287      #C: (#struct){
   288        b: (#struct){ |((#struct){
   289            type: (string){ "a" }
   290            x: (string){ "" }
   291          }, (#struct){
   292            type: (string){ "b" }
   293            x: (string){ string }
   294          }) }
   295      }
   296      e: (struct){
   297        foobar: (#struct){
   298          b: (#struct){
   299            type: (string){ "b" }
   300            x: (string){ "foobar" }
   301          }
   302        }
   303      }
   304    }
   305  }
   306  -- out/compile --
   307  --- in.cue
   308  {
   309    a: (*1|int)
   310    aa: (*1|*2|int)
   311    b: ({
   312      name: "int"
   313      val: int
   314    }|{
   315      name: "str"
   316      val: string
   317    })
   318    d: (〈0;b〉 & {
   319      val: 3
   320    })
   321    c: (〈0;b〉 & {
   322      name: "int"
   323      val: 3
   324    })
   325    e: (〈0;b〉 & {
   326      val: "foo"
   327    })
   328    f: (〈0;b〉 & {
   329      name: "str"
   330      val: 3
   331    })
   332    e1: {
   333      a: (null|{
   334        bar: 2
   335      })
   336      b: (〈0;a〉 & {}).bar
   337    }
   338    d1: {
   339      a: ((null|{
   340        c: 1
   341      }) & {})
   342      b: ({} & (null|{
   343        c: 1
   344      }))
   345    }
   346    d2: {
   347      a: (([
   348        ...,
   349      ]|{
   350        c: 1
   351      }) & {})
   352      b: ({} & ([
   353        ...,
   354      ]|{
   355        c: 1
   356      }))
   357    }
   358    d3: {
   359      a: ((string|{
   360        c: 1
   361      }) & {})
   362      b: ({} & (string|{
   363        c: 1
   364      }))
   365    }
   366    d4: {
   367      a: ((string|{
   368        c: 1
   369      }) & {})
   370      b: ({} & (string|{
   371        c: 1
   372      }))
   373    }
   374    d5: {
   375      a: ((number|{
   376        c: 1
   377      }) & {})
   378      b: ({} & (number|{
   379        c: 1
   380      }))
   381    }
   382    d6: {
   383      a: ((int|{
   384        c: 1
   385      }) & {})
   386      b: ({} & (int|{
   387        c: 1
   388      }))
   389    }
   390    t10: {
   391      schema: 〈0;test〉
   392      schema: (string|{
   393        name: string
   394      })
   395      #A: {
   396        (string|{
   397          name: string
   398        })
   399      }
   400      test: {
   401        name: "Test"
   402      }
   403      test: 〈0;#A〉
   404    }
   405    t10: {
   406      schema: (string|{
   407        name: string
   408      })
   409      schema: 〈0;test〉
   410      #A: {
   411        (string|{
   412          name: string
   413        })
   414      }
   415      test: {
   416        name: "Test"
   417      }
   418      test: 〈0;#A〉
   419    }
   420    t10: {
   421      #A: {
   422        (string|{
   423          name: string
   424        })
   425      }
   426      test: {
   427        name: "Test"
   428      }
   429      test: 〈0;#A〉
   430      schema: (string|{
   431        name: string
   432      })
   433      schema: 〈0;test〉
   434    }
   435    t11: {
   436      a: 〈0;#A〉
   437      a: 〈0;b〉
   438      b: (〈0;#A〉 & [
   439        "b",
   440      ])
   441      #A: ([
   442        ("a"|"b"),
   443      ]|{})
   444    }
   445    t11: {
   446      b: (〈0;#A〉 & [
   447        "b",
   448      ])
   449      #A: ([
   450        ("a"|"b"),
   451      ]|{})
   452      a: 〈0;b〉
   453      a: 〈0;#A〉
   454    }
   455    cross: {
   456      a: (*"word"|string)
   457      a: (string|*"word")
   458    }
   459    d100: {
   460      i: (null|{
   461        bar: 2
   462      })
   463      j: 〈0;i〉.bar
   464    }
   465    issue641: {
   466      #A: {
   467        type: "a"
   468        x: ""
   469      }
   470      #B: {
   471        type: "b"
   472        x: string
   473      }
   474      #C: {
   475        b: (〈1;#A〉|〈1;#B〉)
   476      }
   477      e: {
   478        [string]: (〈1;#C〉 & {
   479          b: (〈2;#A〉|〈2;#B〉)
   480        })
   481      }
   482      e: {
   483        foobar: (〈1;#C〉 & {
   484          b: (〈2;#B〉 & {
   485            x: "foobar"
   486          })
   487        })
   488      }
   489    }
   490  }