...

Text file src/cuelang.org/go/cue/testdata/comprehensions/iferror.txtar

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

     1-- in.cue --
     2a: {b: 2, c: int}
     3
     4wrongConcreteType: {
     5	if a.b {
     6		2
     7	}
     8}
     9
    10wrongType: {
    11	if a.c {
    12		2
    13	}
    14}
    15
    16incomplete: {
    17	if a.d {
    18		2
    19	}
    20}
    21
    22incomplete: {
    23	list: [1, 2, 3]
    24	for x in list if a.d {
    25		x
    26	}
    27}
    28
    29// Issue #809
    30useDefault: {
    31	a: {
    32		x: *"foo" | string
    33		if x != _|_ {
    34			y: x
    35		}
    36	}
    37
    38	issue809: {
    39		#A: {
    40			a: string
    41			b: *a | string
    42		}
    43
    44		s: [Name=string]: #A & {a: Name}
    45		s: bar:           _
    46
    47		foo: [
    48			for _, a in s if a.b != _|_ {a},
    49		]
    50	}
    51}
    52
    53issue1972: {
    54	err1: {
    55		#patchs: []
    56		#patchs
    57
    58		#someCondition: _
    59		if #someCondition {
    60		}
    61	}
    62	err1: {
    63		someCondition: _
    64		patchs: [...{}]
    65		patchs
    66		if someCondition {
    67			patchs: _
    68		}
    69	}
    70}
    71-- out/compile --
    72--- in.cue
    73{
    74  a: {
    75    b: 2
    76    c: int
    77  }
    78  wrongConcreteType: {
    79    if 〈1;a〉.b {
    80      2
    81    }
    82  }
    83  wrongType: {
    84    if 〈1;a〉.c {
    85      2
    86    }
    87  }
    88  incomplete: {
    89    if 〈1;a〉.d {
    90      2
    91    }
    92  }
    93  incomplete: {
    94    list: [
    95      1,
    96      2,
    97      3,
    98    ]
    99    for _, x in 〈0;list〉 if 〈2;a〉.d {
   100      〈1;x〉
   101    }
   102  }
   103  useDefault: {
   104    a: {
   105      x: (*"foo"|string)
   106      if (〈0;x〉 != _|_(explicit error (_|_ literal) in source)) {
   107        y: 〈1;x〉
   108      }
   109    }
   110    issue809: {
   111      #A: {
   112        a: string
   113        b: (*〈0;a〉|string)
   114      }
   115      s: {
   116        [string]: (〈1;#A〉 & {
   117          a: 〈1;-〉
   118        })
   119      }
   120      s: {
   121        bar: _
   122      }
   123      foo: [
   124        for _, a in 〈1;s〉 if (〈0;a〉.b != _|_(explicit error (_|_ literal) in source)) {
   125          〈1;a〉
   126        },
   127      ]
   128    }
   129  }
   130  issue1972: {
   131    err1: {
   132      #patchs: []
   133      〈0;#patchs〉
   134      #someCondition: _
   135      if 〈0;#someCondition〉 {}
   136    }
   137    err1: {
   138      someCondition: _
   139      patchs: [
   140        ...{},
   141      ]
   142      〈0;patchs〉
   143      if 〈0;someCondition〉 {
   144        patchs: _
   145      }
   146    }
   147  }
   148}
   149-- out/eval/stats --
   150Leaks:  0
   151Freed:  43
   152Reused: 35
   153Allocs: 8
   154Retain: 14
   155
   156Unifications: 33
   157Conjuncts:    66
   158Disjuncts:    57
   159-- out/eval --
   160Errors:
   161issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   162    ./in.cue:54:12
   163    ./in.cue:61:8
   164wrongConcreteType: cannot use 2 (type int) as type bool:
   165    ./in.cue:4:2
   166    ./in.cue:1:8
   167wrongType: cannot use int (type int) as type bool:
   168    ./in.cue:10:2
   169    ./in.cue:1:14
   170issue1972.err1: invalid list index someCondition (type string):
   171    ./in.cue:65:6
   172
   173Result:
   174(_|_){
   175  // [eval]
   176  a: (struct){
   177    b: (int){ 2 }
   178    c: (int){ int }
   179  }
   180  wrongConcreteType: (_|_){
   181    // [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
   182    //     ./in.cue:4:2
   183    //     ./in.cue:1:8
   184  }
   185  wrongType: (_|_){
   186    // [eval] wrongType: cannot use int (type int) as type bool:
   187    //     ./in.cue:10:2
   188    //     ./in.cue:1:14
   189  }
   190  incomplete: (_|_){
   191    // [incomplete] incomplete: undefined field: d:
   192    //     ./in.cue:16:7
   193    // incomplete: undefined field: d:
   194    //     ./in.cue:23:21
   195    list: (#list){
   196      0: (int){ 1 }
   197      1: (int){ 2 }
   198      2: (int){ 3 }
   199    }
   200  }
   201  useDefault: (struct){
   202    a: (struct){
   203      x: (string){ |(*(string){ "foo" }, (string){ string }) }
   204      y: (string){ |(*(string){ "foo" }, (string){ string }) }
   205    }
   206    issue809: (struct){
   207      #A: (#struct){
   208        a: (string){ string }
   209        b: (string){ string }
   210      }
   211      s: (struct){
   212        bar: (#struct){
   213          a: (string){ "bar" }
   214          b: (string){ |(*(string){ "bar" }, (string){ string }) }
   215        }
   216      }
   217      foo: (#list){
   218        0: (#struct){
   219          a: (string){ "bar" }
   220          b: (string){ |(*(string){ "bar" }, (string){ string }) }
   221        }
   222      }
   223    }
   224  }
   225  issue1972: (_|_){
   226    // [eval]
   227    err1: (_|_){
   228      // [eval] issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   229      //     ./in.cue:54:12
   230      //     ./in.cue:61:8
   231      // issue1972.err1: invalid list index someCondition (type string):
   232      //     ./in.cue:65:6
   233      #patchs: (#list){
   234      }
   235      someCondition: (_){ _ }
   236      patchs: (list){
   237      }
   238      #someCondition: (_){ _ }
   239    }
   240  }
   241}

View as plain text