cuelang.org/go@v0.13.0/cue/testdata/eval/openinline.txtar (about)

     1  # This test is important in locking in the closedness behavior
     2  # of evalv2, where inline structs cause some closedness errors
     3  # to be ignored. evalv3 mimics this behavior for the sake of
     4  # backwards compatibility and not breaking existing users.
     5  
     6  -- cue.mod/module.cue --
     7  module: "mod.test"
     8  language: version: "v0.9.0"
     9  -- in.cue --
    10  import (
    11  	pkg "foo.com/example"
    12  )
    13  
    14  // This test tests that closeness errors are eliminated that occur within an
    15  // inline struct.
    16  inlineErr: {
    17  	#D: {a: 1}
    18  
    19  	// Allow a closedness error that occurs within an inline struct.
    20  	def: x: (#D & {b: 2}).b
    21  }
    22  
    23  // These tests test that selecting into an inlined struct recursively opens this
    24  // struct in OpenInline.
    25  outerErr: {
    26  	_inToOut: {
    27  		in: _
    28  		out: in.foo
    29  	}
    30  
    31  	// The closedness of #Inner should be opened in OpenInline mode.
    32  	issue3534: {
    33  		#Inner: foo: minor: 2
    34  		#Outer: version: { major: 1, ... }
    35  
    36  		t1: #Outer
    37  		t1: version: (_inToOut & {in: #Inner}).out
    38  	}
    39  
    40  	// Test that the same principle works with the close builtin.
    41  	usingClose: {
    42  		// Same as above, but with an additional level of nesting.
    43  		#Inner:  foo: close({minor: 2})
    44  		#Outer: version: { major: 1, ... }
    45  
    46  		t1: #Outer
    47  		t1: version: (_inToOut & {in: #Inner}).out
    48  	}
    49  
    50  	// Test that the mechanism still works with extra nesting: the closedness of
    51  	// #Inner should be opened recursively in OpenInline mode.
    52  	extraNesting: {
    53  		// Same as above, but with an additional level of nesting.
    54  		#Inner: foo: x: minor: 2
    55  		#Outer: version: x: { major: 1, ... }
    56  
    57  		t1: #Outer
    58  		t1: version: (_inToOut & {in: #Inner}).out
    59  	}
    60  }
    61  
    62  // Here OpenInline does _not_ erase the error, as the error is already present
    63  // in the referred definitions.
    64  
    65  // faulty struct referenced from package
    66  refFromPkg: (pkg.#E).b
    67  
    68  refFromLet: {
    69  	let X = {
    70  		#D: a: 2
    71  		#E: #D & {b: 1}
    72  	}
    73  	x: (X.#E).b
    74  }
    75  
    76  -- cue.mod/pkg/foo.com/example/example.cue --
    77  package example
    78  
    79  #D: a: 1
    80  #E: #D & {b: 1}
    81  
    82  -- out/eval/stats --
    83  Leaks:  18
    84  Freed:  73
    85  Reused: 69
    86  Allocs: 22
    87  Retain: 37
    88  
    89  Unifications: 91
    90  Conjuncts:    141
    91  Disjuncts:    107
    92  -- out/evalalpha --
    93  Errors:
    94  outerErr.usingClose.t1.version.major: field not allowed:
    95      ./in.cue:35:22
    96  
    97  Result:
    98  (_|_){
    99    // [eval]
   100    inlineErr: (struct){
   101      #D: (#struct){
   102        a: (int){ 1 }
   103      }
   104      def: (struct){
   105        x: (int){ 2 }
   106      }
   107    }
   108    outerErr: (_|_){
   109      // [eval]
   110      _inToOut: (struct){
   111        in: (_){ _ }
   112        out: (_|_){
   113          // [incomplete] outerErr._inToOut.out: in.foo undefined as in is incomplete (type _):
   114          //     ./in.cue:19:8
   115        }
   116      }
   117      issue3534: (struct){
   118        #Inner: (#struct){
   119          foo: (#struct){
   120            minor: (int){ 2 }
   121          }
   122        }
   123        #Outer: (#struct){
   124          version: (#struct){
   125            major: (int){ 1 }
   126          }
   127        }
   128        t1: (#struct){
   129          version: (#struct){
   130            major: (int){ 1 }
   131            minor: (int){ 2 }
   132          }
   133        }
   134      }
   135      usingClose: (_|_){
   136        // [eval]
   137        #Inner: (#struct){
   138          foo: (#struct){
   139            minor: (int){ 2 }
   140          }
   141        }
   142        #Outer: (#struct){
   143          version: (#struct){
   144            major: (int){ 1 }
   145          }
   146        }
   147        t1: (_|_){
   148          // [eval]
   149          version: (_|_){
   150            // [eval]
   151            major: (_|_){
   152              // [eval] outerErr.usingClose.t1.version.major: field not allowed:
   153              //     ./in.cue:35:22
   154            }
   155            minor: (int){ 2 }
   156          }
   157        }
   158      }
   159      extraNesting: (struct){
   160        #Inner: (#struct){
   161          foo: (#struct){
   162            x: (#struct){
   163              minor: (int){ 2 }
   164            }
   165          }
   166        }
   167        #Outer: (#struct){
   168          version: (#struct){
   169            x: (#struct){
   170              major: (int){ 1 }
   171            }
   172          }
   173        }
   174        t1: (#struct){
   175          version: (#struct){
   176            x: (#struct){
   177              major: (int){ 1 }
   178              minor: (int){ 2 }
   179            }
   180          }
   181        }
   182      }
   183    }
   184    refFromPkg: (int){ 1 }
   185    refFromLet: (struct){
   186      let X#1 = (_|_){
   187        // [eval]
   188        #D: (#struct){
   189          a: (int){ 2 }
   190        }
   191        #E: (_|_){
   192          // [eval]
   193          b: (_|_){
   194            // [eval] refFromLet.X.#E.b: field not allowed:
   195            //     ./in.cue:62:13
   196          }
   197          a: (int){ 2 }
   198        }
   199      }
   200      x: (int){ 1 }
   201    }
   202  }
   203  -- diff/-out/evalalpha<==>+out/eval --
   204  diff old new
   205  --- old
   206  +++ new
   207  @@ -1,10 +1,6 @@
   208   Errors:
   209   outerErr.usingClose.t1.version.major: field not allowed:
   210  -    ./in.cue:19:8
   211  -    ./in.cue:34:23
   212       ./in.cue:35:22
   213  -    ./in.cue:37:7
   214  -    ./in.cue:38:16
   215   
   216   Result:
   217   (_|_){
   218  @@ -62,11 +58,7 @@
   219             // [eval]
   220             major: (_|_){
   221               // [eval] outerErr.usingClose.t1.version.major: field not allowed:
   222  -            //     ./in.cue:19:8
   223  -            //     ./in.cue:34:23
   224               //     ./in.cue:35:22
   225  -            //     ./in.cue:37:7
   226  -            //     ./in.cue:38:16
   227             }
   228             minor: (int){ 2 }
   229           }
   230  @@ -106,13 +98,11 @@
   231         }
   232         #E: (_|_){
   233           // [eval]
   234  -        a: (int){ 2 }
   235           b: (_|_){
   236             // [eval] refFromLet.X.#E.b: field not allowed:
   237  -          //     ./in.cue:61:7
   238  -          //     ./in.cue:62:7
   239             //     ./in.cue:62:13
   240           }
   241  +        a: (int){ 2 }
   242         }
   243       }
   244       x: (int){ 1 }
   245  -- out/eval --
   246  Errors:
   247  outerErr.usingClose.t1.version.major: field not allowed:
   248      ./in.cue:19:8
   249      ./in.cue:34:23
   250      ./in.cue:35:22
   251      ./in.cue:37:7
   252      ./in.cue:38:16
   253  
   254  Result:
   255  (_|_){
   256    // [eval]
   257    inlineErr: (struct){
   258      #D: (#struct){
   259        a: (int){ 1 }
   260      }
   261      def: (struct){
   262        x: (int){ 2 }
   263      }
   264    }
   265    outerErr: (_|_){
   266      // [eval]
   267      _inToOut: (struct){
   268        in: (_){ _ }
   269        out: (_|_){
   270          // [incomplete] outerErr._inToOut.out: in.foo undefined as in is incomplete (type _):
   271          //     ./in.cue:19:8
   272        }
   273      }
   274      issue3534: (struct){
   275        #Inner: (#struct){
   276          foo: (#struct){
   277            minor: (int){ 2 }
   278          }
   279        }
   280        #Outer: (#struct){
   281          version: (#struct){
   282            major: (int){ 1 }
   283          }
   284        }
   285        t1: (#struct){
   286          version: (#struct){
   287            major: (int){ 1 }
   288            minor: (int){ 2 }
   289          }
   290        }
   291      }
   292      usingClose: (_|_){
   293        // [eval]
   294        #Inner: (#struct){
   295          foo: (#struct){
   296            minor: (int){ 2 }
   297          }
   298        }
   299        #Outer: (#struct){
   300          version: (#struct){
   301            major: (int){ 1 }
   302          }
   303        }
   304        t1: (_|_){
   305          // [eval]
   306          version: (_|_){
   307            // [eval]
   308            major: (_|_){
   309              // [eval] outerErr.usingClose.t1.version.major: field not allowed:
   310              //     ./in.cue:19:8
   311              //     ./in.cue:34:23
   312              //     ./in.cue:35:22
   313              //     ./in.cue:37:7
   314              //     ./in.cue:38:16
   315            }
   316            minor: (int){ 2 }
   317          }
   318        }
   319      }
   320      extraNesting: (struct){
   321        #Inner: (#struct){
   322          foo: (#struct){
   323            x: (#struct){
   324              minor: (int){ 2 }
   325            }
   326          }
   327        }
   328        #Outer: (#struct){
   329          version: (#struct){
   330            x: (#struct){
   331              major: (int){ 1 }
   332            }
   333          }
   334        }
   335        t1: (#struct){
   336          version: (#struct){
   337            x: (#struct){
   338              major: (int){ 1 }
   339              minor: (int){ 2 }
   340            }
   341          }
   342        }
   343      }
   344    }
   345    refFromPkg: (int){ 1 }
   346    refFromLet: (struct){
   347      let X#1 = (_|_){
   348        // [eval]
   349        #D: (#struct){
   350          a: (int){ 2 }
   351        }
   352        #E: (_|_){
   353          // [eval]
   354          a: (int){ 2 }
   355          b: (_|_){
   356            // [eval] refFromLet.X.#E.b: field not allowed:
   357            //     ./in.cue:61:7
   358            //     ./in.cue:62:7
   359            //     ./in.cue:62:13
   360          }
   361        }
   362      }
   363      x: (int){ 1 }
   364    }
   365  }
   366  -- out/compile --
   367  --- in.cue
   368  {
   369    inlineErr: {
   370      #D: {
   371        a: 1
   372      }
   373      def: {
   374        x: (〈1;#D〉 & {
   375          b: 2
   376        }).b
   377      }
   378    }
   379    outerErr: {
   380      _inToOut: {
   381        in: _
   382        out: 〈0;in〉.foo
   383      }
   384      issue3534: {
   385        #Inner: {
   386          foo: {
   387            minor: 2
   388          }
   389        }
   390        #Outer: {
   391          version: {
   392            major: 1
   393            ...
   394          }
   395        }
   396        t1: 〈0;#Outer〉
   397        t1: {
   398          version: (〈2;_inToOut〉 & {
   399            in: 〈2;#Inner〉
   400          }).out
   401        }
   402      }
   403      usingClose: {
   404        #Inner: {
   405          foo: close({
   406            minor: 2
   407          })
   408        }
   409        #Outer: {
   410          version: {
   411            major: 1
   412            ...
   413          }
   414        }
   415        t1: 〈0;#Outer〉
   416        t1: {
   417          version: (〈2;_inToOut〉 & {
   418            in: 〈2;#Inner〉
   419          }).out
   420        }
   421      }
   422      extraNesting: {
   423        #Inner: {
   424          foo: {
   425            x: {
   426              minor: 2
   427            }
   428          }
   429        }
   430        #Outer: {
   431          version: {
   432            x: {
   433              major: 1
   434              ...
   435            }
   436          }
   437        }
   438        t1: 〈0;#Outer〉
   439        t1: {
   440          version: (〈2;_inToOut〉 & {
   441            in: 〈2;#Inner〉
   442          }).out
   443        }
   444      }
   445    }
   446    refFromPkg: 〈import;"foo.com/example"〉.#E.b
   447    refFromLet: {
   448      let X#1 = {
   449        #D: {
   450          a: 2
   451        }
   452        #E: (〈0;#D〉 & {
   453          b: 1
   454        })
   455      }
   456      x: 〈0;let X#1〉.#E.b
   457    }
   458  }