cuelang.org/go@v0.13.0/cue/testdata/builtins/incomplete.txtar (about)

     1  -- in.cue --
     2  import (
     3  	"list"
     4  	"strings"
     5  	"text/template"
     6  )
     7  
     8  list1: {
     9  	// Note that Top is not incomplete, only its first element is.
    10  	// We allow FlattenN to proceed and pass on the incomplete values.
    11  	Out1: list.FlattenN(Top, 1)
    12  	Out2: [...] & list.FlattenN(Top, 1)
    13  	Out3: list.FlattenN(Top, 1) & [...]
    14  
    15  	// This evaluates to a list with an incomplete element.
    16  	Top: [
    17  		[for _, F in _Sub {F}],
    18  	]
    19  
    20  	_Sub: a.b
    21  	a: {} // b does not
    22  }
    23  
    24  list2: {
    25  	Out1: list.FlattenN(_Top, 1)
    26  	Out2: [...] & list.FlattenN(_Top, 1)
    27  	Out3: list.FlattenN(_Top, 1) & [...]
    28  
    29  	// This evaluates to a list with an incomplete element.
    30  	_Top: [
    31  		for _, F in #Sub {F},
    32  	]
    33  
    34  	#Sub: a.b
    35  
    36  	a: {} // b does not
    37  }
    38  
    39  value1: {
    40  	a: len('sf' | 'dd')
    41  }
    42  
    43  value2: {
    44  	len('sf' | 'dd')
    45  }
    46  
    47  incompleteArgDecimalList: {
    48  	a: #a & {param: 123}
    49  	#a: {
    50  		param:       int
    51  		transformed: +param
    52  		max:         list.Max([transformed])
    53  	}
    54  }
    55  
    56  incompleteArgStringList: {
    57  	a: #a & {param: "123"}
    58  	#a: {
    59  		param:       string
    60  		transformed: param + ""
    61  		joined:      strings.Join([transformed], "-")
    62  	}
    63  }
    64  
    65  incompleteList: {
    66  	x:       _
    67  	decimal: list.Max(x)
    68  	str:     strings.Join(x, "")
    69  }
    70  
    71  // TODO: add better error positions.
    72  incompleteListError: {
    73  	x:       y + []
    74  	y:       _
    75  	decimal: list.Max(x)
    76  	str:     strings.Join(x, "")
    77  }
    78  
    79  badListType: {
    80  	x:       2
    81  	decimal: list.Max(x)
    82  	str:     strings.Join(x, "")
    83  }
    84  
    85  badListError: {
    86  	x:       2 + y
    87  	y:       "foo"
    88  	decimal: list.Max(x)
    89  	str:     strings.Join(x, "")
    90  }
    91  
    92  // Issue #1095
    93  // Preserve combined error severity for multiple errors.
    94  multipleErrors: {
    95  	#T: {
    96  		params: {
    97  			x: string
    98  			y: string
    99  		}
   100  		out: template.Execute("{{.x}} {{.y}}", params)
   101  	}
   102  }
   103  -- out/evalalpha/stats --
   104  Leaks:  83
   105  Freed:  0
   106  Reused: 0
   107  Allocs: 83
   108  Retain: 0
   109  
   110  Unifications: 79
   111  Conjuncts:    101
   112  Disjuncts:    4
   113  
   114  CloseIDElems: 8
   115  NumCloseIDs: 9
   116  -- diff/-out/evalalpha/stats<==>+out/eval/stats --
   117  diff old new
   118  --- old
   119  +++ new
   120  @@ -1,9 +1,12 @@
   121  -Leaks:  8
   122  -Freed:  115
   123  -Reused: 110
   124  -Allocs: 13
   125  -Retain: 58
   126  -
   127  -Unifications: 103
   128  -Conjuncts:    255
   129  -Disjuncts:    150
   130  +Leaks:  83
   131  +Freed:  0
   132  +Reused: 0
   133  +Allocs: 83
   134  +Retain: 0
   135  +
   136  +Unifications: 79
   137  +Conjuncts:    101
   138  +Disjuncts:    4
   139  +
   140  +CloseIDElems: 8
   141  +NumCloseIDs: 9
   142  -- out/eval/stats --
   143  Leaks:  8
   144  Freed:  115
   145  Reused: 110
   146  Allocs: 13
   147  Retain: 58
   148  
   149  Unifications: 103
   150  Conjuncts:    255
   151  Disjuncts:    150
   152  -- out/evalalpha --
   153  Errors:
   154  badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
   155      ./in.cue:79:11
   156  badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
   157      ./in.cue:79:11
   158  badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   159      ./in.cue:85:11
   160      ./in.cue:86:11
   161  
   162  Result:
   163  (_|_){
   164    // [eval]
   165    list1: (struct){
   166      Out1: (#list){
   167        0: (_|_){
   168          // [incomplete] list1._Sub: undefined field: b:
   169          //     ./in.cue:19:10
   170        }
   171      }
   172      Out2: (#list){
   173        0: (_|_){
   174          // [incomplete] list1._Sub: undefined field: b:
   175          //     ./in.cue:19:10
   176        }
   177      }
   178      Out3: (#list){
   179        0: (_|_){
   180          // [incomplete] list1._Sub: undefined field: b:
   181          //     ./in.cue:19:10
   182        }
   183      }
   184      Top: (#list){
   185        0: (_|_){
   186          // [incomplete] list1._Sub: undefined field: b:
   187          //     ./in.cue:19:10
   188        }
   189      }
   190      _Sub: (_|_){
   191        // [incomplete] list1._Sub: undefined field: b:
   192        //     ./in.cue:19:10
   193      }
   194      a: (struct){
   195      }
   196    }
   197    list2: (struct){
   198      Out1: (_|_){
   199        // [incomplete] list2.#Sub: undefined field: b:
   200        //     ./in.cue:33:10
   201      }
   202      Out2: (_|_){
   203        // [incomplete] list2.#Sub: undefined field: b:
   204        //     ./in.cue:33:10
   205      }
   206      Out3: (_|_){
   207        // [incomplete] list2.#Sub: undefined field: b:
   208        //     ./in.cue:33:10
   209      }
   210      _Top: (_|_){
   211        // [incomplete] list2.#Sub: undefined field: b:
   212        //     ./in.cue:33:10
   213      }
   214      #Sub: (_|_){
   215        // [incomplete] list2.#Sub: undefined field: b:
   216        //     ./in.cue:33:10
   217      }
   218      a: (struct){
   219      }
   220    }
   221    value1: (struct){
   222      a: (_|_){
   223        // [incomplete] value1.a: unresolved disjunction 'sf' | 'dd' (type bytes):
   224        //     ./in.cue:39:5
   225      }
   226    }
   227    value2: (_|_){
   228      // [incomplete] value2: unresolved disjunction 'sf' | 'dd' (type bytes):
   229      //     ./in.cue:43:2
   230    }
   231    incompleteArgDecimalList: (struct){
   232      a: (#struct){
   233        param: (int){ 123 }
   234        transformed: (int){ 123 }
   235        max: (int){ 123 }
   236      }
   237      #a: (#struct){
   238        param: (int){ int }
   239        transformed: (_|_){
   240          // [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
   241          //     ./in.cue:50:17
   242        }
   243        max: (_|_){
   244          // [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
   245          //     ./in.cue:50:17
   246        }
   247      }
   248    }
   249    incompleteArgStringList: (struct){
   250      a: (#struct){
   251        param: (string){ "123" }
   252        transformed: (string){ "123" }
   253        joined: (string){ "123" }
   254      }
   255      #a: (#struct){
   256        param: (string){ string }
   257        transformed: (_|_){
   258          // [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
   259          //     ./in.cue:59:16
   260          //     ./in.cue:58:16
   261        }
   262        joined: (_|_){
   263          // [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
   264          //     ./in.cue:59:16
   265          //     ./in.cue:58:16
   266        }
   267      }
   268    }
   269    incompleteList: (struct){
   270      x: (_){ _ }
   271      decimal: (_|_){
   272        // [incomplete] incompleteList.decimal: non-concrete list for argument 0:
   273        //     ./in.cue:66:11
   274      }
   275      str: (_|_){
   276        // [incomplete] incompleteList.str: non-concrete list for argument 0:
   277        //     ./in.cue:67:11
   278      }
   279    }
   280    incompleteListError: (struct){
   281      x: (_|_){
   282        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   283        //     ./in.cue:72:11
   284        //     ./in.cue:73:11
   285      }
   286      y: (_){ _ }
   287      decimal: (_|_){
   288        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   289        //     ./in.cue:72:11
   290        //     ./in.cue:73:11
   291      }
   292      str: (_|_){
   293        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   294        //     ./in.cue:72:11
   295        //     ./in.cue:73:11
   296      }
   297    }
   298    badListType: (_|_){
   299      // [eval]
   300      x: (int){ 2 }
   301      decimal: (_|_){
   302        // [eval] badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
   303        //     ./in.cue:79:11
   304      }
   305      str: (_|_){
   306        // [eval] badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
   307        //     ./in.cue:79:11
   308      }
   309    }
   310    badListError: (_|_){
   311      // [eval]
   312      x: (_|_){
   313        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   314        //     ./in.cue:85:11
   315        //     ./in.cue:86:11
   316      }
   317      y: (string){ "foo" }
   318      decimal: (_|_){
   319        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   320        //     ./in.cue:85:11
   321        //     ./in.cue:86:11
   322      }
   323      str: (_|_){
   324        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   325        //     ./in.cue:85:11
   326        //     ./in.cue:86:11
   327      }
   328    }
   329    multipleErrors: (struct){
   330      #T: (#struct){
   331        params: (#struct){
   332          x: (string){ string }
   333          y: (string){ string }
   334        }
   335        out: (_|_){
   336          // [incomplete] multipleErrors.#T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
   337          //     ./in.cue:99:8
   338          //     ./in.cue:96:4
   339        }
   340      }
   341    }
   342  }
   343  -- diff/-out/evalalpha<==>+out/eval --
   344  diff old new
   345  --- old
   346  +++ new
   347  @@ -89,7 +89,7 @@
   348           //     ./in.cue:50:17
   349         }
   350         max: (_|_){
   351  -        // [incomplete] incompleteArgDecimalList.#a.0: operand param of '+' not concrete (was int):
   352  +        // [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
   353           //     ./in.cue:50:17
   354         }
   355       }
   356  @@ -108,7 +108,7 @@
   357           //     ./in.cue:58:16
   358         }
   359         joined: (_|_){
   360  -        // [incomplete] incompleteArgStringList.#a.0: non-concrete value string in operand to +:
   361  +        // [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
   362           //     ./in.cue:59:16
   363           //     ./in.cue:58:16
   364         }
   365  @@ -129,15 +129,18 @@
   366       x: (_|_){
   367         // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   368         //     ./in.cue:72:11
   369  +      //     ./in.cue:73:11
   370       }
   371       y: (_){ _ }
   372       decimal: (_|_){
   373         // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   374         //     ./in.cue:72:11
   375  -    }
   376  -    str: (_|_){
   377  -      // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   378  -      //     ./in.cue:72:11
   379  +      //     ./in.cue:73:11
   380  +    }
   381  +    str: (_|_){
   382  +      // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   383  +      //     ./in.cue:72:11
   384  +      //     ./in.cue:73:11
   385       }
   386     }
   387     badListType: (_|_){
   388  -- out/eval --
   389  Errors:
   390  badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
   391      ./in.cue:79:11
   392  badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
   393      ./in.cue:79:11
   394  badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   395      ./in.cue:85:11
   396      ./in.cue:86:11
   397  
   398  Result:
   399  (_|_){
   400    // [eval]
   401    list1: (struct){
   402      Out1: (#list){
   403        0: (_|_){
   404          // [incomplete] list1._Sub: undefined field: b:
   405          //     ./in.cue:19:10
   406        }
   407      }
   408      Out2: (#list){
   409        0: (_|_){
   410          // [incomplete] list1._Sub: undefined field: b:
   411          //     ./in.cue:19:10
   412        }
   413      }
   414      Out3: (#list){
   415        0: (_|_){
   416          // [incomplete] list1._Sub: undefined field: b:
   417          //     ./in.cue:19:10
   418        }
   419      }
   420      Top: (#list){
   421        0: (_|_){
   422          // [incomplete] list1._Sub: undefined field: b:
   423          //     ./in.cue:19:10
   424        }
   425      }
   426      _Sub: (_|_){
   427        // [incomplete] list1._Sub: undefined field: b:
   428        //     ./in.cue:19:10
   429      }
   430      a: (struct){
   431      }
   432    }
   433    list2: (struct){
   434      Out1: (_|_){
   435        // [incomplete] list2.#Sub: undefined field: b:
   436        //     ./in.cue:33:10
   437      }
   438      Out2: (_|_){
   439        // [incomplete] list2.#Sub: undefined field: b:
   440        //     ./in.cue:33:10
   441      }
   442      Out3: (_|_){
   443        // [incomplete] list2.#Sub: undefined field: b:
   444        //     ./in.cue:33:10
   445      }
   446      _Top: (_|_){
   447        // [incomplete] list2.#Sub: undefined field: b:
   448        //     ./in.cue:33:10
   449      }
   450      #Sub: (_|_){
   451        // [incomplete] list2.#Sub: undefined field: b:
   452        //     ./in.cue:33:10
   453      }
   454      a: (struct){
   455      }
   456    }
   457    value1: (struct){
   458      a: (_|_){
   459        // [incomplete] value1.a: unresolved disjunction 'sf' | 'dd' (type bytes):
   460        //     ./in.cue:39:5
   461      }
   462    }
   463    value2: (_|_){
   464      // [incomplete] value2: unresolved disjunction 'sf' | 'dd' (type bytes):
   465      //     ./in.cue:43:2
   466    }
   467    incompleteArgDecimalList: (struct){
   468      a: (#struct){
   469        param: (int){ 123 }
   470        transformed: (int){ 123 }
   471        max: (int){ 123 }
   472      }
   473      #a: (#struct){
   474        param: (int){ int }
   475        transformed: (_|_){
   476          // [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
   477          //     ./in.cue:50:17
   478        }
   479        max: (_|_){
   480          // [incomplete] incompleteArgDecimalList.#a.0: operand param of '+' not concrete (was int):
   481          //     ./in.cue:50:17
   482        }
   483      }
   484    }
   485    incompleteArgStringList: (struct){
   486      a: (#struct){
   487        param: (string){ "123" }
   488        transformed: (string){ "123" }
   489        joined: (string){ "123" }
   490      }
   491      #a: (#struct){
   492        param: (string){ string }
   493        transformed: (_|_){
   494          // [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
   495          //     ./in.cue:59:16
   496          //     ./in.cue:58:16
   497        }
   498        joined: (_|_){
   499          // [incomplete] incompleteArgStringList.#a.0: non-concrete value string in operand to +:
   500          //     ./in.cue:59:16
   501          //     ./in.cue:58:16
   502        }
   503      }
   504    }
   505    incompleteList: (struct){
   506      x: (_){ _ }
   507      decimal: (_|_){
   508        // [incomplete] incompleteList.decimal: non-concrete list for argument 0:
   509        //     ./in.cue:66:11
   510      }
   511      str: (_|_){
   512        // [incomplete] incompleteList.str: non-concrete list for argument 0:
   513        //     ./in.cue:67:11
   514      }
   515    }
   516    incompleteListError: (struct){
   517      x: (_|_){
   518        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   519        //     ./in.cue:72:11
   520      }
   521      y: (_){ _ }
   522      decimal: (_|_){
   523        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   524        //     ./in.cue:72:11
   525      }
   526      str: (_|_){
   527        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   528        //     ./in.cue:72:11
   529      }
   530    }
   531    badListType: (_|_){
   532      // [eval]
   533      x: (int){ 2 }
   534      decimal: (_|_){
   535        // [eval] badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
   536        //     ./in.cue:79:11
   537      }
   538      str: (_|_){
   539        // [eval] badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
   540        //     ./in.cue:79:11
   541      }
   542    }
   543    badListError: (_|_){
   544      // [eval]
   545      x: (_|_){
   546        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   547        //     ./in.cue:85:11
   548        //     ./in.cue:86:11
   549      }
   550      y: (string){ "foo" }
   551      decimal: (_|_){
   552        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   553        //     ./in.cue:85:11
   554        //     ./in.cue:86:11
   555      }
   556      str: (_|_){
   557        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   558        //     ./in.cue:85:11
   559        //     ./in.cue:86:11
   560      }
   561    }
   562    multipleErrors: (struct){
   563      #T: (#struct){
   564        params: (#struct){
   565          x: (string){ string }
   566          y: (string){ string }
   567        }
   568        out: (_|_){
   569          // [incomplete] multipleErrors.#T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
   570          //     ./in.cue:99:8
   571          //     ./in.cue:96:4
   572        }
   573      }
   574    }
   575  }
   576  -- out/compile --
   577  --- in.cue
   578  {
   579    list1: {
   580      Out1: 〈import;list〉.FlattenN(〈0;Top〉, 1)
   581      Out2: ([
   582        ...,
   583      ] & 〈import;list〉.FlattenN(〈0;Top〉, 1))
   584      Out3: (〈import;list〉.FlattenN(〈0;Top〉, 1) & [
   585        ...,
   586      ])
   587      Top: [
   588        [
   589          for _, F in 〈2;_Sub〉 {
   590            〈1;F〉
   591          },
   592        ],
   593      ]
   594      _Sub: 〈0;a〉.b
   595      a: {}
   596    }
   597    list2: {
   598      Out1: 〈import;list〉.FlattenN(〈0;_Top〉, 1)
   599      Out2: ([
   600        ...,
   601      ] & 〈import;list〉.FlattenN(〈0;_Top〉, 1))
   602      Out3: (〈import;list〉.FlattenN(〈0;_Top〉, 1) & [
   603        ...,
   604      ])
   605      _Top: [
   606        for _, F in 〈1;#Sub〉 {
   607          〈1;F〉
   608        },
   609      ]
   610      #Sub: 〈0;a〉.b
   611      a: {}
   612    }
   613    value1: {
   614      a: len(('sf'|'dd'))
   615    }
   616    value2: {
   617      len(('sf'|'dd'))
   618    }
   619    incompleteArgDecimalList: {
   620      a: (〈0;#a〉 & {
   621        param: 123
   622      })
   623      #a: {
   624        param: int
   625        transformed: +〈0;param〉
   626        max: 〈import;list〉.Max([
   627          〈1;transformed〉,
   628        ])
   629      }
   630    }
   631    incompleteArgStringList: {
   632      a: (〈0;#a〉 & {
   633        param: "123"
   634      })
   635      #a: {
   636        param: string
   637        transformed: (〈0;param〉 + "")
   638        joined: 〈import;strings〉.Join([
   639          〈1;transformed〉,
   640        ], "-")
   641      }
   642    }
   643    incompleteList: {
   644      x: _
   645      decimal: 〈import;list〉.Max(〈0;x〉)
   646      str: 〈import;strings〉.Join(〈0;x〉, "")
   647    }
   648    incompleteListError: {
   649      x: (〈0;y〉 + [])
   650      y: _
   651      decimal: 〈import;list〉.Max(〈0;x〉)
   652      str: 〈import;strings〉.Join(〈0;x〉, "")
   653    }
   654    badListType: {
   655      x: 2
   656      decimal: 〈import;list〉.Max(〈0;x〉)
   657      str: 〈import;strings〉.Join(〈0;x〉, "")
   658    }
   659    badListError: {
   660      x: (2 + 〈0;y〉)
   661      y: "foo"
   662      decimal: 〈import;list〉.Max(〈0;x〉)
   663      str: 〈import;strings〉.Join(〈0;x〉, "")
   664    }
   665    multipleErrors: {
   666      #T: {
   667        params: {
   668          x: string
   669          y: string
   670        }
   671        out: 〈import;"text/template"〉.Execute("{{.x}} {{.y}}", 〈0;params〉)
   672      }
   673    }
   674  }