cuelang.org/go@v0.13.0/cue/testdata/scalars/embed.txtar (about)

     1  // Issue ##739
     2  
     3  -- in.cue --
     4  import "strings"
     5  import "list"
     6  
     7  intEmbed: {
     8  	a1: {
     9  		2
    10  	}
    11  	a2: {
    12  		v: {
    13  			3
    14  			#foo: a2.v + 1
    15  		}
    16  		w: v
    17  		x: v.#foo
    18  	}
    19  	a3: a1 + a2.v
    20  }
    21  
    22  listEmbed: {
    23  	a1: {
    24  		2
    25  	}
    26  	b3: {
    27  		[1, 2]
    28  		#foo: 1
    29  	}
    30  	b4: list.Concat([b3, b3])
    31  	b5: b3[1]
    32  	b6: b3[5]
    33  	b7: b4[a1] // 1
    34  }
    35  
    36  stringEmbed: {
    37  	s1: {
    38  		"foo"
    39  		#bar: "bar"
    40  	}
    41  	s2: [ s1, {s1.#bar, #baz: 4}]
    42  	s3: strings.Join(s2, "--")
    43  }
    44  
    45  outPattern: {
    46  	sum: {
    47  		out: #a + #b
    48  		#a:  int
    49  		#b:  int
    50  	}
    51  	used: sum & {#a: 1, #b: 3}
    52  }
    53  
    54  arithmetic: {
    55  	sum: {
    56  		#a + #b
    57  		#a: int
    58  		#b: int
    59  	}
    60  	a1: (sum & {_, #a:          1, #b: 3}) + 2
    61  	a2: 2 + (sum & {_, #a:      1, #b: 3})
    62  	a3: 2 + (2 + (sum & {_, #a: 1, #b: 3}))
    63  }
    64  
    65  defCheck: {
    66  	a: {
    67  		#def: 1
    68  	}
    69  	b: a.#def
    70  }
    71  
    72  optionalExists: {
    73  	string | {
    74  		value?: string
    75  
    76  		if value != _|_ {
    77  			other: int
    78  		}
    79  	}
    80  }
    81  
    82  optionalCheck: {
    83  	thing: string | {
    84  		value?: string
    85  
    86  		if value != _|_ {
    87  			other: int
    88  		}
    89  	}
    90  
    91  	thing: {
    92  		value: "some string"
    93  		other: 3
    94  	}
    95  }
    96  
    97  hidden: {
    98  	issue794: {
    99  		_foo: "foo"
   100  		[_foo]
   101  	}
   102  }
   103  
   104  -- issue2113.cue --
   105  // In all these tests, embedded scalars should resolve without error.
   106  merged: t1: p1: {
   107  	#fn: { #in2: _, _ }
   108  	#fn: { #in2: c1: string, #in2.c1 }
   109  	x: #fn & {#in2: {c1: "V 1"}, _}
   110  }
   111  merged: t1: p2: {
   112  	#fn: { #in2: c1: string, #in2.c1 }
   113  	#fn: { #in2: _, _ }
   114  	x: #fn & {#in2: {c1: "V 1"}, _}
   115  }
   116  merged: t1: p3: {
   117  	x: #fn & {#in2: {c1: "V 1"}, _}
   118  	#fn: { #in2: c1: string, #in2.c1 }
   119  	#fn: { #in2: _, _ }
   120  }
   121  merged: t2: p1: {
   122  	#fn: { #in2: {}, _ }
   123  	#fn: { #in2: c1: string, #in2.c1 }
   124  	x: #fn & {#in2: {c1: "V 1"}, _}
   125  }
   126  merged: t2: p2: {
   127  	#fn: { #in2: c1: string, #in2.c1 }
   128  	#fn: { #in2: {}, _ }
   129  	x: #fn & {#in2: {c1: "V 1"}, _}
   130  }
   131  merged: t2: p3: {
   132  	x: #fn & {#in2: {c1: "V 1"}, _}
   133  	#fn: { #in2: c1: string, #in2.c1 }
   134  	#fn: { #in2: {}, _ }
   135  }
   136  
   137  -- issue2163.cue --
   138  selfRefInEmbed: t1: {
   139  	#Func: {
   140  		#in: _
   141  		_
   142  	}
   143  	#fn: #Func
   144  	#fn: {
   145  		#in: _
   146  	
   147  		(#Func & {
   148  			_foo: #in
   149  			"buzz"
   150  		}) + "fiz"
   151  	}
   152  }
   153  
   154  -- out/eval/stats --
   155  Leaks:  10
   156  Freed:  130
   157  Reused: 123
   158  Allocs: 17
   159  Retain: 57
   160  
   161  Unifications: 136
   162  Conjuncts:    304
   163  Disjuncts:    173
   164  -- out/evalalpha --
   165  Errors:
   166  listEmbed.b6: index out of range [5] with length 2:
   167      ./in.cue:29:9
   168  
   169  Result:
   170  (_|_){
   171    // [eval]
   172    intEmbed: (struct){
   173      a1: (int){ 2 }
   174      a2: (struct){
   175        v: (int){
   176          3
   177          #foo: (int){ 4 }
   178        }
   179        w: ~(intEmbed.a2.v)
   180        x: (int){ 4 }
   181      }
   182      a3: (int){ 5 }
   183    }
   184    listEmbed: (_|_){
   185      // [eval]
   186      a1: (int){ 2 }
   187      b3: (#list){
   188        #foo: (int){ 1 }
   189        0: (int){ 1 }
   190        1: (int){ 2 }
   191      }
   192      b4: (#list){
   193        0: (int){ 1 }
   194        1: (int){ 2 }
   195        2: (int){ 1 }
   196        3: (int){ 2 }
   197      }
   198      b5: (int){ 2 }
   199      b6: (_|_){
   200        // [eval] listEmbed.b6: index out of range [5] with length 2:
   201        //     ./in.cue:29:9
   202      }
   203      b7: (int){ 1 }
   204    }
   205    stringEmbed: (struct){
   206      s1: (string){
   207        "foo"
   208        #bar: (string){ "bar" }
   209      }
   210      s2: (#list){
   211        0: ~(stringEmbed.s1)
   212        1: (string){
   213          "bar"
   214          #baz: (int){ 4 }
   215        }
   216      }
   217      s3: (string){ "foo--bar" }
   218    }
   219    outPattern: (struct){
   220      sum: (struct){
   221        out: (_|_){
   222          // [incomplete] outPattern.sum.out: non-concrete value int in operand to +:
   223          //     ./in.cue:44:8
   224          //     ./in.cue:45:8
   225        }
   226        #a: (int){ int }
   227        #b: (int){ int }
   228      }
   229      used: (struct){
   230        #a: (int){ 1 }
   231        #b: (int){ 3 }
   232        out: (int){ 4 }
   233      }
   234    }
   235    arithmetic: (struct){
   236      sum: (_|_){
   237        // [incomplete] arithmetic.sum: non-concrete value int in operand to +:
   238        //     ./in.cue:53:3
   239        //     ./in.cue:54:7
   240        #a: (int){ int }
   241        #b: (int){ int }
   242      }
   243      a1: (int){ 6 }
   244      a2: (int){ 6 }
   245      a3: (int){ 8 }
   246    }
   247    defCheck: (struct){
   248      a: (struct){
   249        #def: (int){ 1 }
   250      }
   251      b: (int){ 1 }
   252    }
   253    optionalExists: ((string|struct)){ |((string){ string }, (struct){
   254        value?: (string){ string }
   255      }) }
   256    optionalCheck: (struct){
   257      thing: (struct){
   258        value: (string){ "some string" }
   259        other: (int){ 3 }
   260      }
   261    }
   262    hidden: (struct){
   263      issue794: (#list){
   264        _foo: (string){ "foo" }
   265        0: (string){ "foo" }
   266      }
   267    }
   268    merged: (struct){
   269      t1: (struct){
   270        p1: (struct){
   271          #fn: (string){
   272            string
   273            #in2: (#struct){
   274              c1: (string){ string }
   275            }
   276          }
   277          x: (string){
   278            "V 1"
   279            #in2: (#struct){
   280              c1: (string){ "V 1" }
   281            }
   282          }
   283        }
   284        p2: (struct){
   285          #fn: (string){
   286            string
   287            #in2: (#struct){
   288              c1: (string){ string }
   289            }
   290          }
   291          x: (string){
   292            "V 1"
   293            #in2: (#struct){
   294              c1: (string){ "V 1" }
   295            }
   296          }
   297        }
   298        p3: (struct){
   299          x: (string){
   300            "V 1"
   301            #in2: (#struct){
   302              c1: (string){ "V 1" }
   303            }
   304          }
   305          #fn: (string){
   306            string
   307            #in2: (#struct){
   308              c1: (string){ string }
   309            }
   310          }
   311        }
   312      }
   313      t2: (struct){
   314        p1: (struct){
   315          #fn: (string){
   316            string
   317            #in2: (#struct){
   318              c1: (string){ string }
   319            }
   320          }
   321          x: (string){
   322            "V 1"
   323            #in2: (#struct){
   324              c1: (string){ "V 1" }
   325            }
   326          }
   327        }
   328        p2: (struct){
   329          #fn: (string){
   330            string
   331            #in2: (#struct){
   332              c1: (string){ string }
   333            }
   334          }
   335          x: (string){
   336            "V 1"
   337            #in2: (#struct){
   338              c1: (string){ "V 1" }
   339            }
   340          }
   341        }
   342        p3: (struct){
   343          x: (string){
   344            "V 1"
   345            #in2: (#struct){
   346              c1: (string){ "V 1" }
   347            }
   348          }
   349          #fn: (string){
   350            string
   351            #in2: (#struct){
   352              c1: (string){ string }
   353            }
   354          }
   355        }
   356      }
   357    }
   358    selfRefInEmbed: (struct){
   359      t1: (struct){
   360        #Func: (_){
   361          _
   362          #in: (_){ _ }
   363        }
   364        #fn: (string){
   365          "buzzfiz"
   366          #in: (_){ _ }
   367        }
   368      }
   369    }
   370  }
   371  -- diff/-out/evalalpha<==>+out/eval --
   372  diff old new
   373  --- old
   374  +++ new
   375  @@ -1,5 +1,5 @@
   376   Errors:
   377  -listEmbed.b6: invalid list index 5 (out of bounds):
   378  +listEmbed.b6: index out of range [5] with length 2:
   379       ./in.cue:29:9
   380   
   381   Result:
   382  @@ -12,10 +12,7 @@
   383           3
   384           #foo: (int){ 4 }
   385         }
   386  -      w: (int){
   387  -        3
   388  -        #foo: (int){ 4 }
   389  -      }
   390  +      w: ~(intEmbed.a2.v)
   391         x: (int){ 4 }
   392       }
   393       a3: (int){ 5 }
   394  @@ -36,7 +33,7 @@
   395       }
   396       b5: (int){ 2 }
   397       b6: (_|_){
   398  -      // [eval] listEmbed.b6: invalid list index 5 (out of bounds):
   399  +      // [eval] listEmbed.b6: index out of range [5] with length 2:
   400         //     ./in.cue:29:9
   401       }
   402       b7: (int){ 1 }
   403  @@ -47,10 +44,7 @@
   404         #bar: (string){ "bar" }
   405       }
   406       s2: (#list){
   407  -      0: (string){
   408  -        "foo"
   409  -        #bar: (string){ "bar" }
   410  -      }
   411  +      0: ~(stringEmbed.s1)
   412         1: (string){
   413           "bar"
   414           #baz: (int){ 4 }
   415  @@ -69,9 +63,9 @@
   416         #b: (int){ int }
   417       }
   418       used: (struct){
   419  -      out: (int){ 4 }
   420         #a: (int){ 1 }
   421         #b: (int){ 3 }
   422  +      out: (int){ 4 }
   423       }
   424     }
   425     arithmetic: (struct){
   426  -- diff/todo/p3 --
   427  Reordering.
   428  -- diff/explanation --
   429  Improved error message.
   430  -- out/eval --
   431  Errors:
   432  listEmbed.b6: invalid list index 5 (out of bounds):
   433      ./in.cue:29:9
   434  
   435  Result:
   436  (_|_){
   437    // [eval]
   438    intEmbed: (struct){
   439      a1: (int){ 2 }
   440      a2: (struct){
   441        v: (int){
   442          3
   443          #foo: (int){ 4 }
   444        }
   445        w: (int){
   446          3
   447          #foo: (int){ 4 }
   448        }
   449        x: (int){ 4 }
   450      }
   451      a3: (int){ 5 }
   452    }
   453    listEmbed: (_|_){
   454      // [eval]
   455      a1: (int){ 2 }
   456      b3: (#list){
   457        #foo: (int){ 1 }
   458        0: (int){ 1 }
   459        1: (int){ 2 }
   460      }
   461      b4: (#list){
   462        0: (int){ 1 }
   463        1: (int){ 2 }
   464        2: (int){ 1 }
   465        3: (int){ 2 }
   466      }
   467      b5: (int){ 2 }
   468      b6: (_|_){
   469        // [eval] listEmbed.b6: invalid list index 5 (out of bounds):
   470        //     ./in.cue:29:9
   471      }
   472      b7: (int){ 1 }
   473    }
   474    stringEmbed: (struct){
   475      s1: (string){
   476        "foo"
   477        #bar: (string){ "bar" }
   478      }
   479      s2: (#list){
   480        0: (string){
   481          "foo"
   482          #bar: (string){ "bar" }
   483        }
   484        1: (string){
   485          "bar"
   486          #baz: (int){ 4 }
   487        }
   488      }
   489      s3: (string){ "foo--bar" }
   490    }
   491    outPattern: (struct){
   492      sum: (struct){
   493        out: (_|_){
   494          // [incomplete] outPattern.sum.out: non-concrete value int in operand to +:
   495          //     ./in.cue:44:8
   496          //     ./in.cue:45:8
   497        }
   498        #a: (int){ int }
   499        #b: (int){ int }
   500      }
   501      used: (struct){
   502        out: (int){ 4 }
   503        #a: (int){ 1 }
   504        #b: (int){ 3 }
   505      }
   506    }
   507    arithmetic: (struct){
   508      sum: (_|_){
   509        // [incomplete] arithmetic.sum: non-concrete value int in operand to +:
   510        //     ./in.cue:53:3
   511        //     ./in.cue:54:7
   512        #a: (int){ int }
   513        #b: (int){ int }
   514      }
   515      a1: (int){ 6 }
   516      a2: (int){ 6 }
   517      a3: (int){ 8 }
   518    }
   519    defCheck: (struct){
   520      a: (struct){
   521        #def: (int){ 1 }
   522      }
   523      b: (int){ 1 }
   524    }
   525    optionalExists: ((string|struct)){ |((string){ string }, (struct){
   526        value?: (string){ string }
   527      }) }
   528    optionalCheck: (struct){
   529      thing: (struct){
   530        value: (string){ "some string" }
   531        other: (int){ 3 }
   532      }
   533    }
   534    hidden: (struct){
   535      issue794: (#list){
   536        _foo: (string){ "foo" }
   537        0: (string){ "foo" }
   538      }
   539    }
   540    merged: (struct){
   541      t1: (struct){
   542        p1: (struct){
   543          #fn: (string){
   544            string
   545            #in2: (#struct){
   546              c1: (string){ string }
   547            }
   548          }
   549          x: (string){
   550            "V 1"
   551            #in2: (#struct){
   552              c1: (string){ "V 1" }
   553            }
   554          }
   555        }
   556        p2: (struct){
   557          #fn: (string){
   558            string
   559            #in2: (#struct){
   560              c1: (string){ string }
   561            }
   562          }
   563          x: (string){
   564            "V 1"
   565            #in2: (#struct){
   566              c1: (string){ "V 1" }
   567            }
   568          }
   569        }
   570        p3: (struct){
   571          x: (string){
   572            "V 1"
   573            #in2: (#struct){
   574              c1: (string){ "V 1" }
   575            }
   576          }
   577          #fn: (string){
   578            string
   579            #in2: (#struct){
   580              c1: (string){ string }
   581            }
   582          }
   583        }
   584      }
   585      t2: (struct){
   586        p1: (struct){
   587          #fn: (string){
   588            string
   589            #in2: (#struct){
   590              c1: (string){ string }
   591            }
   592          }
   593          x: (string){
   594            "V 1"
   595            #in2: (#struct){
   596              c1: (string){ "V 1" }
   597            }
   598          }
   599        }
   600        p2: (struct){
   601          #fn: (string){
   602            string
   603            #in2: (#struct){
   604              c1: (string){ string }
   605            }
   606          }
   607          x: (string){
   608            "V 1"
   609            #in2: (#struct){
   610              c1: (string){ "V 1" }
   611            }
   612          }
   613        }
   614        p3: (struct){
   615          x: (string){
   616            "V 1"
   617            #in2: (#struct){
   618              c1: (string){ "V 1" }
   619            }
   620          }
   621          #fn: (string){
   622            string
   623            #in2: (#struct){
   624              c1: (string){ string }
   625            }
   626          }
   627        }
   628      }
   629    }
   630    selfRefInEmbed: (struct){
   631      t1: (struct){
   632        #Func: (_){
   633          _
   634          #in: (_){ _ }
   635        }
   636        #fn: (string){
   637          "buzzfiz"
   638          #in: (_){ _ }
   639        }
   640      }
   641    }
   642  }
   643  -- out/compile --
   644  --- in.cue
   645  {
   646    intEmbed: {
   647      a1: {
   648        2
   649      }
   650      a2: {
   651        v: {
   652          3
   653          #foo: (〈2;a2〉.v + 1)
   654        }
   655        w: 〈0;v〉
   656        x: 〈0;v〉.#foo
   657      }
   658      a3: (〈0;a1〉 + 〈0;a2〉.v)
   659    }
   660    listEmbed: {
   661      a1: {
   662        2
   663      }
   664      b3: {
   665        [
   666          1,
   667          2,
   668        ]
   669        #foo: 1
   670      }
   671      b4: 〈import;list〉.Concat([
   672        〈1;b3〉,
   673        〈1;b3〉,
   674      ])
   675      b5: 〈0;b3〉[1]
   676      b6: 〈0;b3〉[5]
   677      b7: 〈0;b4〉[〈0;a1〉]
   678    }
   679    stringEmbed: {
   680      s1: {
   681        "foo"
   682        #bar: "bar"
   683      }
   684      s2: [
   685        〈1;s1〉,
   686        {
   687          〈2;s1〉.#bar
   688          #baz: 4
   689        },
   690      ]
   691      s3: 〈import;strings〉.Join(〈0;s2〉, "--")
   692    }
   693    outPattern: {
   694      sum: {
   695        out: (〈0;#a〉 + 〈0;#b〉)
   696        #a: int
   697        #b: int
   698      }
   699      used: (〈0;sum〉 & {
   700        #a: 1
   701        #b: 3
   702      })
   703    }
   704    arithmetic: {
   705      sum: {
   706        (〈0;#a〉 + 〈0;#b〉)
   707        #a: int
   708        #b: int
   709      }
   710      a1: ((〈0;sum〉 & {
   711        _
   712        #a: 1
   713        #b: 3
   714      }) + 2)
   715      a2: (2 + (〈0;sum〉 & {
   716        _
   717        #a: 1
   718        #b: 3
   719      }))
   720      a3: (2 + (2 + (〈0;sum〉 & {
   721        _
   722        #a: 1
   723        #b: 3
   724      })))
   725    }
   726    defCheck: {
   727      a: {
   728        #def: 1
   729      }
   730      b: 〈0;a〉.#def
   731    }
   732    optionalExists: {
   733      (string|{
   734        value?: string
   735        if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) {
   736          other: int
   737        }
   738      })
   739    }
   740    optionalCheck: {
   741      thing: (string|{
   742        value?: string
   743        if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) {
   744          other: int
   745        }
   746      })
   747      thing: {
   748        value: "some string"
   749        other: 3
   750      }
   751    }
   752    hidden: {
   753      issue794: {
   754        _foo: "foo"
   755        [
   756          〈1;_foo〉,
   757        ]
   758      }
   759    }
   760  }
   761  --- issue2113.cue
   762  {
   763    merged: {
   764      t1: {
   765        p1: {
   766          #fn: {
   767            #in2: _
   768            _
   769          }
   770          #fn: {
   771            #in2: {
   772              c1: string
   773            }
   774            〈0;#in2〉.c1
   775          }
   776          x: (〈0;#fn〉 & {
   777            #in2: {
   778              c1: "V 1"
   779            }
   780            _
   781          })
   782        }
   783      }
   784    }
   785    merged: {
   786      t1: {
   787        p2: {
   788          #fn: {
   789            #in2: {
   790              c1: string
   791            }
   792            〈0;#in2〉.c1
   793          }
   794          #fn: {
   795            #in2: _
   796            _
   797          }
   798          x: (〈0;#fn〉 & {
   799            #in2: {
   800              c1: "V 1"
   801            }
   802            _
   803          })
   804        }
   805      }
   806    }
   807    merged: {
   808      t1: {
   809        p3: {
   810          x: (〈0;#fn〉 & {
   811            #in2: {
   812              c1: "V 1"
   813            }
   814            _
   815          })
   816          #fn: {
   817            #in2: {
   818              c1: string
   819            }
   820            〈0;#in2〉.c1
   821          }
   822          #fn: {
   823            #in2: _
   824            _
   825          }
   826        }
   827      }
   828    }
   829    merged: {
   830      t2: {
   831        p1: {
   832          #fn: {
   833            #in2: {}
   834            _
   835          }
   836          #fn: {
   837            #in2: {
   838              c1: string
   839            }
   840            〈0;#in2〉.c1
   841          }
   842          x: (〈0;#fn〉 & {
   843            #in2: {
   844              c1: "V 1"
   845            }
   846            _
   847          })
   848        }
   849      }
   850    }
   851    merged: {
   852      t2: {
   853        p2: {
   854          #fn: {
   855            #in2: {
   856              c1: string
   857            }
   858            〈0;#in2〉.c1
   859          }
   860          #fn: {
   861            #in2: {}
   862            _
   863          }
   864          x: (〈0;#fn〉 & {
   865            #in2: {
   866              c1: "V 1"
   867            }
   868            _
   869          })
   870        }
   871      }
   872    }
   873    merged: {
   874      t2: {
   875        p3: {
   876          x: (〈0;#fn〉 & {
   877            #in2: {
   878              c1: "V 1"
   879            }
   880            _
   881          })
   882          #fn: {
   883            #in2: {
   884              c1: string
   885            }
   886            〈0;#in2〉.c1
   887          }
   888          #fn: {
   889            #in2: {}
   890            _
   891          }
   892        }
   893      }
   894    }
   895  }
   896  --- issue2163.cue
   897  {
   898    selfRefInEmbed: {
   899      t1: {
   900        #Func: {
   901          #in: _
   902          _
   903        }
   904        #fn: 〈0;#Func〉
   905        #fn: {
   906          #in: _
   907          ((〈1;#Func〉 & {
   908            _foo: 〈1;#in〉
   909            "buzz"
   910          }) + "fiz")
   911        }
   912      }
   913    }
   914  }