github.com/solo-io/cue@v0.4.7/cue/testdata/builtins/incomplete.txtar (about)

     1  -- in.cue --
     2  import (
     3    "list"
     4    "strings"
     5  )
     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      a: {} // b does not
    36  }
    37  
    38  value1: {
    39      a: len('sf' | 'dd')
    40  }
    41  
    42  value2: {
    43      len('sf' | 'dd')
    44  }
    45  
    46  incompleteArgDecimalList: {
    47      a: #a & {param: 123}
    48      #a: {
    49          param: int
    50          transformed: +param
    51          max: list.Max([transformed])
    52      }
    53  }
    54  
    55  incompleteArgStringList: {
    56      a: #a & {param: "123"}
    57      #a: {
    58          param: string
    59          transformed: param+""
    60          joined: strings.Join([transformed], "-")
    61      }
    62  }
    63  
    64  incompleteList: {
    65      x: _
    66      decimal: list.Max(x)
    67      str:     strings.Join(x, "")
    68  }
    69  
    70  incompleteListError: {
    71      x: y + []
    72      y: _
    73      decimal: list.Max(x)
    74      str:     strings.Join(x, "")
    75  }
    76  
    77  badListType: {
    78      x: 2
    79      decimal: list.Max(x)
    80      str:     strings.Join(x, "")
    81  }
    82  
    83  badListError: {
    84      x: 2 + y
    85      y: "foo"
    86      decimal: list.Max(x)
    87      str:     strings.Join(x, "")
    88  }
    89  
    90  -- out/eval --
    91  Errors:
    92  badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
    93      ./in.cue:77:8
    94  badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
    95      ./in.cue:77:8
    96  badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
    97      ./in.cue:83:8
    98      ./in.cue:84:8
    99  
   100  Result:
   101  (_|_){
   102    // [eval]
   103    list1: (struct){
   104      Out1: (#list){
   105        0: (_|_){
   106          // [cycle] cycle error:
   107          //     ./in.cue:16:23
   108        }
   109      }
   110      Out2: (#list){
   111        0: (_|_){
   112          // [cycle] cycle error:
   113          //     ./in.cue:16:23
   114        }
   115      }
   116      Out3: (#list){
   117        0: (_|_){
   118          // [cycle] cycle error:
   119          //     ./in.cue:16:23
   120        }
   121      }
   122      Top: (#list){
   123        0: (_|_){
   124          // [cycle] cycle error:
   125          //     ./in.cue:16:23
   126        }
   127      }
   128      _Sub: (_|_){
   129        // [incomplete] list1._Sub: undefined field: b:
   130        //     ./in.cue:19:13
   131      }
   132      a: (struct){
   133      }
   134    }
   135    list2: (struct){
   136      Out1: (_|_){
   137        // [cycle] cycle error:
   138        //     ./in.cue:30:21
   139      }
   140      Out2: (_|_){
   141        // [cycle] cycle error:
   142        //     ./in.cue:30:21
   143      }
   144      Out3: (_|_){
   145        // [cycle] cycle error:
   146        //     ./in.cue:30:21
   147      }
   148      _Top: (_|_){
   149        // [cycle] cycle error:
   150        //     ./in.cue:30:21
   151      }
   152      #Sub: (_|_){
   153        // [incomplete] list2.#Sub: undefined field: b:
   154        //     ./in.cue:33:13
   155      }
   156      a: (struct){
   157      }
   158    }
   159    value1: (struct){
   160      a: (_|_){
   161        // [incomplete] value1.a: unresolved disjunction 'sf' | 'dd' (type bytes):
   162        //     ./in.cue:38:8
   163      }
   164    }
   165    value2: (_|_){
   166      // [incomplete] value2: unresolved disjunction 'sf' | 'dd' (type bytes):
   167      //     ./in.cue:42:5
   168    }
   169    incompleteArgDecimalList: (struct){
   170      a: (#struct){
   171        param: (int){ 123 }
   172        transformed: (int){ 123 }
   173        max: (int){ 123 }
   174      }
   175      #a: (#struct){
   176        param: (int){ int }
   177        transformed: (_|_){
   178          // [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
   179          //     ./in.cue:49:23
   180        }
   181        max: (_|_){
   182          // [incomplete] 0: operand param of '+' not concrete (was int):
   183          //     ./in.cue:49:23
   184        }
   185      }
   186    }
   187    incompleteArgStringList: (struct){
   188      a: (#struct){
   189        param: (string){ "123" }
   190        transformed: (string){ "123" }
   191        joined: (string){ "123" }
   192      }
   193      #a: (#struct){
   194        param: (string){ string }
   195        transformed: (_|_){
   196          // [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
   197          //     ./in.cue:58:22
   198          //     ./in.cue:57:9
   199        }
   200        joined: (_|_){
   201          // [incomplete] 0: non-concrete value string in operand to +:
   202          //     ./in.cue:58:22
   203          //     ./in.cue:57:9
   204        }
   205      }
   206    }
   207    incompleteList: (struct){
   208      x: (_){ _ }
   209      decimal: (_|_){
   210        // [incomplete] incompleteList.decimal: non-concrete list for argument 0:
   211        //     ./in.cue:65:14
   212      }
   213      str: (_|_){
   214        // [incomplete] incompleteList.str: non-concrete list for argument 0:
   215        //     ./in.cue:66:14
   216      }
   217    }
   218    incompleteListError: (struct){
   219      x: (_|_){
   220        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   221        //     ./in.cue:70:8
   222        //     ./in.cue:71:5
   223      }
   224      y: (_){ _ }
   225      decimal: (_|_){
   226        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   227        //     ./in.cue:70:8
   228        //     ./in.cue:71:5
   229      }
   230      str: (_|_){
   231        // [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
   232        //     ./in.cue:70:8
   233        //     ./in.cue:71:5
   234      }
   235    }
   236    badListType: (_|_){
   237      // [eval]
   238      x: (int){ 2 }
   239      decimal: (_|_){
   240        // [eval] badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
   241        //     ./in.cue:77:8
   242      }
   243      str: (_|_){
   244        // [eval] badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
   245        //     ./in.cue:77:8
   246      }
   247    }
   248    badListError: (_|_){
   249      // [eval]
   250      x: (_|_){
   251        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   252        //     ./in.cue:83:8
   253        //     ./in.cue:84:8
   254      }
   255      y: (string){ "foo" }
   256      decimal: (_|_){
   257        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   258        //     ./in.cue:83:8
   259        //     ./in.cue:84:8
   260      }
   261      str: (_|_){
   262        // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
   263        //     ./in.cue:83:8
   264        //     ./in.cue:84:8
   265      }
   266    }
   267  }
   268  -- out/compile --
   269  --- in.cue
   270  {
   271    list1: {
   272      Out1: 〈import;list〉.FlattenN(〈0;Top〉, 1)
   273      Out2: ([
   274        ...,
   275      ] & 〈import;list〉.FlattenN(〈0;Top〉, 1))
   276      Out3: (〈import;list〉.FlattenN(〈0;Top〉, 1) & [
   277        ...,
   278      ])
   279      Top: [
   280        [
   281          for _, F in 〈0;_Sub〉 {
   282            〈1;F〉
   283          },
   284        ],
   285      ]
   286      _Sub: 〈0;a〉.b
   287      a: {}
   288    }
   289    list2: {
   290      Out1: 〈import;list〉.FlattenN(〈0;_Top〉, 1)
   291      Out2: ([
   292        ...,
   293      ] & 〈import;list〉.FlattenN(〈0;_Top〉, 1))
   294      Out3: (〈import;list〉.FlattenN(〈0;_Top〉, 1) & [
   295        ...,
   296      ])
   297      _Top: [
   298        for _, F in 〈0;#Sub〉 {
   299          〈1;F〉
   300        },
   301      ]
   302      #Sub: 〈0;a〉.b
   303      a: {}
   304    }
   305    value1: {
   306      a: len(('sf'|'dd'))
   307    }
   308    value2: {
   309      len(('sf'|'dd'))
   310    }
   311    incompleteArgDecimalList: {
   312      a: (〈0;#a〉 & {
   313        param: 123
   314      })
   315      #a: {
   316        param: int
   317        transformed: +〈0;param〉
   318        max: 〈import;list〉.Max([
   319          〈0;transformed〉,
   320        ])
   321      }
   322    }
   323    incompleteArgStringList: {
   324      a: (〈0;#a〉 & {
   325        param: "123"
   326      })
   327      #a: {
   328        param: string
   329        transformed: (〈0;param〉 + "")
   330        joined: 〈import;strings〉.Join([
   331          〈0;transformed〉,
   332        ], "-")
   333      }
   334    }
   335    incompleteList: {
   336      x: _
   337      decimal: 〈import;list〉.Max(〈0;x〉)
   338      str: 〈import;strings〉.Join(〈0;x〉, "")
   339    }
   340    incompleteListError: {
   341      x: (〈0;y〉 + [])
   342      y: _
   343      decimal: 〈import;list〉.Max(〈0;x〉)
   344      str: 〈import;strings〉.Join(〈0;x〉, "")
   345    }
   346    badListType: {
   347      x: 2
   348      decimal: 〈import;list〉.Max(〈0;x〉)
   349      str: 〈import;strings〉.Join(〈0;x〉, "")
   350    }
   351    badListError: {
   352      x: (2 + 〈0;y〉)
   353      y: "foo"
   354      decimal: 〈import;list〉.Max(〈0;x〉)
   355      str: 〈import;strings〉.Join(〈0;x〉, "")
   356    }
   357  }