cuelang.org/go@v0.13.0/cue/testdata/definitions/026_combined_definitions.txtar (about)

     1  #name: combined definitions
     2  #evalPartial
     3  -- in.cue --
     4  // Allow combining of structs within a definition
     5  #D1: {
     6  	env: a: "A"
     7  	env: b: "B"
     8  	#def: {a: "A"}
     9  	#def: {b: "B"}
    10  }
    11  
    12  d1: #D1 & {env: c: "C"}
    13  
    14  #D2: {
    15  	a: int
    16  }
    17  #D2: {
    18  	b: int
    19  }
    20  
    21  #D3: {
    22  	env: a: "A"
    23  }
    24  #D3: {
    25  	env: b: "B"
    26  }
    27  
    28  #D4: {
    29  	env: #DC
    30  	env: b: int
    31  }
    32  
    33  #DC: {a: int}
    34  -- out/def --
    35  // Allow combining of structs within a definition
    36  #D1: {
    37  	env: {
    38  		a: "A"
    39  		b: "B"
    40  	}
    41  	#def: {
    42  		a: "A"
    43  		b: "B"
    44  	}
    45  }
    46  d1: #D1 & {
    47  	env: {
    48  		c: "C"
    49  	}
    50  }
    51  #D2: {
    52  	a: int
    53  	b: int
    54  }
    55  #D3: {
    56  	env: {
    57  		a: "A"
    58  		b: "B"
    59  	}
    60  }
    61  #D4: {
    62  	env: _|_ // field "b" not allowed in closed struct
    63  }
    64  #DC: {
    65  	a: int
    66  }
    67  -- out/legacy-debug --
    68  <0>{#D1: <1>C{env: <2>C{a: "A", b: "B"}, #def: <3>C{a: "A", b: "B"}}, d1: <4>C{env: _|_("C":field "c" not allowed in closed struct), #def: <5>C{a: "A", b: "B"}}, #D2: <6>C{a: int, b: int}, #D3: <7>C{env: <8>C{a: "A", b: "B"}}, #D4: <9>C{env: _|_(int:field "b" not allowed in closed struct)}, #DC: <10>C{a: int}}
    69  -- out/compile --
    70  --- in.cue
    71  {
    72    #D1: {
    73      env: {
    74        a: "A"
    75      }
    76      env: {
    77        b: "B"
    78      }
    79      #def: {
    80        a: "A"
    81      }
    82      #def: {
    83        b: "B"
    84      }
    85    }
    86    d1: (〈0;#D1〉 & {
    87      env: {
    88        c: "C"
    89      }
    90    })
    91    #D2: {
    92      a: int
    93    }
    94    #D2: {
    95      b: int
    96    }
    97    #D3: {
    98      env: {
    99        a: "A"
   100      }
   101    }
   102    #D3: {
   103      env: {
   104        b: "B"
   105      }
   106    }
   107    #D4: {
   108      env: 〈1;#DC〉
   109      env: {
   110        b: int
   111      }
   112    }
   113    #DC: {
   114      a: int
   115    }
   116  }
   117  -- out/eval/stats --
   118  Leaks:  0
   119  Freed:  29
   120  Reused: 24
   121  Allocs: 5
   122  Retain: 1
   123  
   124  Unifications: 29
   125  Conjuncts:    41
   126  Disjuncts:    30
   127  -- out/evalalpha --
   128  Errors:
   129  #D4.env.b: field not allowed:
   130      ./in.cue:27:7
   131  d1.env.c: field not allowed:
   132      ./in.cue:9:17
   133  
   134  Result:
   135  (_|_){
   136    // [eval]
   137    #D1: (#struct){
   138      env: (#struct){
   139        a: (string){ "A" }
   140        b: (string){ "B" }
   141      }
   142      #def: (#struct){
   143        a: (string){ "A" }
   144        b: (string){ "B" }
   145      }
   146    }
   147    d1: (_|_){
   148      // [eval]
   149      env: (_|_){
   150        // [eval]
   151        c: (_|_){
   152          // [eval] d1.env.c: field not allowed:
   153          //     ./in.cue:9:17
   154        }
   155        a: (string){ "A" }
   156        b: (string){ "B" }
   157      }
   158      #def: (#struct){
   159        a: (string){ "A" }
   160        b: (string){ "B" }
   161      }
   162    }
   163    #D2: (#struct){
   164      a: (int){ int }
   165      b: (int){ int }
   166    }
   167    #D3: (#struct){
   168      env: (#struct){
   169        a: (string){ "A" }
   170        b: (string){ "B" }
   171      }
   172    }
   173    #D4: (_|_){
   174      // [eval]
   175      env: (_|_){
   176        // [eval]
   177        b: (_|_){
   178          // [eval] #D4.env.b: field not allowed:
   179          //     ./in.cue:27:7
   180        }
   181        a: (int){ int }
   182      }
   183    }
   184    #DC: (#struct){
   185      a: (int){ int }
   186    }
   187  }
   188  -- diff/-out/evalalpha<==>+out/eval --
   189  diff old new
   190  --- old
   191  +++ new
   192  @@ -1,12 +1,7 @@
   193   Errors:
   194   #D4.env.b: field not allowed:
   195  -    ./in.cue:26:7
   196       ./in.cue:27:7
   197  -    ./in.cue:30:6
   198   d1.env.c: field not allowed:
   199  -    ./in.cue:3:7
   200  -    ./in.cue:4:7
   201  -    ./in.cue:9:5
   202       ./in.cue:9:17
   203   
   204   Result:
   205  @@ -26,15 +21,12 @@
   206       // [eval]
   207       env: (_|_){
   208         // [eval]
   209  -      a: (string){ "A" }
   210  -      b: (string){ "B" }
   211         c: (_|_){
   212           // [eval] d1.env.c: field not allowed:
   213  -        //     ./in.cue:3:7
   214  -        //     ./in.cue:4:7
   215  -        //     ./in.cue:9:5
   216           //     ./in.cue:9:17
   217         }
   218  +      a: (string){ "A" }
   219  +      b: (string){ "B" }
   220       }
   221       #def: (#struct){
   222         a: (string){ "A" }
   223  @@ -55,13 +47,11 @@
   224       // [eval]
   225       env: (_|_){
   226         // [eval]
   227  -      a: (int){ int }
   228         b: (_|_){
   229           // [eval] #D4.env.b: field not allowed:
   230  -        //     ./in.cue:26:7
   231           //     ./in.cue:27:7
   232  -        //     ./in.cue:30:6
   233  -      }
   234  +      }
   235  +      a: (int){ int }
   236       }
   237     }
   238     #DC: (#struct){
   239  -- diff/todo/p2 --
   240  Missing positions
   241  -- diff/todo/p3 --
   242  Reordering
   243  -- out/eval --
   244  Errors:
   245  #D4.env.b: field not allowed:
   246      ./in.cue:26:7
   247      ./in.cue:27:7
   248      ./in.cue:30:6
   249  d1.env.c: field not allowed:
   250      ./in.cue:3:7
   251      ./in.cue:4:7
   252      ./in.cue:9:5
   253      ./in.cue:9:17
   254  
   255  Result:
   256  (_|_){
   257    // [eval]
   258    #D1: (#struct){
   259      env: (#struct){
   260        a: (string){ "A" }
   261        b: (string){ "B" }
   262      }
   263      #def: (#struct){
   264        a: (string){ "A" }
   265        b: (string){ "B" }
   266      }
   267    }
   268    d1: (_|_){
   269      // [eval]
   270      env: (_|_){
   271        // [eval]
   272        a: (string){ "A" }
   273        b: (string){ "B" }
   274        c: (_|_){
   275          // [eval] d1.env.c: field not allowed:
   276          //     ./in.cue:3:7
   277          //     ./in.cue:4:7
   278          //     ./in.cue:9:5
   279          //     ./in.cue:9:17
   280        }
   281      }
   282      #def: (#struct){
   283        a: (string){ "A" }
   284        b: (string){ "B" }
   285      }
   286    }
   287    #D2: (#struct){
   288      a: (int){ int }
   289      b: (int){ int }
   290    }
   291    #D3: (#struct){
   292      env: (#struct){
   293        a: (string){ "A" }
   294        b: (string){ "B" }
   295      }
   296    }
   297    #D4: (_|_){
   298      // [eval]
   299      env: (_|_){
   300        // [eval]
   301        a: (int){ int }
   302        b: (_|_){
   303          // [eval] #D4.env.b: field not allowed:
   304          //     ./in.cue:26:7
   305          //     ./in.cue:27:7
   306          //     ./in.cue:30:6
   307        }
   308      }
   309    }
   310    #DC: (#struct){
   311      a: (int){ int }
   312    }
   313  }