...

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

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

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

View as plain text