...

Text file src/cuelang.org/go/cue/testdata/builtins/incomplete.txtar

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

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

View as plain text