cuelang.org/go@v0.10.1/cue/testdata/eval/issue3330.txtar (about)

     1  -- in.cue --
     2  import "list"
     3  
     4  issue3330: {
     5  	#A: {
     6  		let empty = {}
     7  	
     8  		// Reference to empty is within the definition that defines it. Closedness
     9  		// thus does not trigger.
    10  		field: null | { n: int }
    11  		field: empty & { n: 3 }
    12  	}
    13  
    14  	out: list.Concat([[#A]])
    15  }
    16  
    17  eliminated: {
    18  	// This test case ensures a definition is only used for the empty struct.
    19  	// This ensures that the elimination of disjuncts is triggered, ensuring
    20  	// the code path that caused the panic in issue3330 is triggered even when
    21  	// the closedness bug that triggered it indirectly is fixed.
    22  	#empty: {}
    23  	x: null | { n: 3 }
    24  	x: #empty & { n: 3 }
    25  	out: len(x)
    26  }
    27  
    28  simplified: {
    29  	// This is a different take on the above bug that demonstrates the issue
    30  	// is only triggered after a definition is referenced.
    31  	#struct: {
    32  		field: { n: 3 } & g
    33  		g: {}
    34  	}
    35  
    36  	out: #struct & {}
    37  }
    38  -- out/eval/stats --
    39  Leaks:  0
    40  Freed:  51
    41  Reused: 42
    42  Allocs: 9
    43  Retain: 3
    44  
    45  Unifications: 41
    46  Conjuncts:    83
    47  Disjuncts:    54
    48  -- out/evalalpha --
    49  Errors:
    50  eliminated.x: conflicting values null and {} (mismatched types null and struct):
    51      ./in.cue:21:10
    52      ./in.cue:22:5
    53  eliminated.x.n: field not allowed:
    54      ./in.cue:23:5
    55      ./in.cue:23:16
    56  
    57  Result:
    58  (_|_){
    59    // [eval]
    60    issue3330: (struct){
    61      #A: (#struct){
    62        let empty#1 = (#struct){
    63        }
    64        field: (#struct){
    65          n: (int){ 3 }
    66        }
    67      }
    68      out: (#list){
    69        0: (#struct){
    70          let empty#1 = (#struct){
    71          }
    72          field: (#struct){
    73            n: (int){ 3 }
    74          }
    75        }
    76      }
    77    }
    78    eliminated: (_|_){
    79      // [eval]
    80      #empty: (#struct){
    81      }
    82      x: (_|_){
    83        // [eval] eliminated.x: conflicting values null and {} (mismatched types null and struct):
    84        //     ./in.cue:21:10
    85        //     ./in.cue:22:5
    86        // eliminated.x.n: field not allowed:
    87        //     ./in.cue:23:5
    88        //     ./in.cue:23:16
    89        n: (_|_){
    90          // [eval] eliminated.x.n: field not allowed:
    91          //     ./in.cue:23:5
    92          //     ./in.cue:23:16
    93        }
    94      }
    95      out: (_|_){
    96        // [eval] eliminated.x: conflicting values null and {} (mismatched types null and struct):
    97        //     ./in.cue:21:10
    98        //     ./in.cue:22:5
    99        // eliminated.x.n: field not allowed:
   100        //     ./in.cue:23:5
   101        //     ./in.cue:23:16
   102      }
   103    }
   104    simplified: (struct){
   105      #struct: (#struct){
   106        field: (#struct){
   107          n: (int){ 3 }
   108        }
   109        g: (#struct){
   110        }
   111      }
   112      out: (#struct){
   113        field: (#struct){
   114          n: (int){ 3 }
   115        }
   116        g: (#struct){
   117        }
   118      }
   119    }
   120  }
   121  -- diff/-out/evalalpha<==>+out/eval --
   122  diff old new
   123  --- old
   124  +++ new
   125  @@ -1,11 +1,8 @@
   126   Errors:
   127  -eliminated.x: 2 errors in empty disjunction:
   128  -eliminated.x: conflicting values null and {n:3} (mismatched types null and struct):
   129  +eliminated.x: conflicting values null and {} (mismatched types null and struct):
   130  +    ./in.cue:21:10
   131       ./in.cue:22:5
   132  -    ./in.cue:23:14
   133   eliminated.x.n: field not allowed:
   134  -    ./in.cue:21:10
   135  -    ./in.cue:22:14
   136       ./in.cue:23:5
   137       ./in.cue:23:16
   138   
   139  @@ -35,31 +32,23 @@
   140       #empty: (#struct){
   141       }
   142       x: (_|_){
   143  -      // [eval] eliminated.x: 2 errors in empty disjunction:
   144  -      // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct):
   145  -      //     ./in.cue:22:5
   146  -      //     ./in.cue:23:14
   147  -      // eliminated.x.n: field not allowed:
   148  -      //     ./in.cue:21:10
   149  -      //     ./in.cue:22:14
   150  +      // [eval] eliminated.x: conflicting values null and {} (mismatched types null and struct):
   151  +      //     ./in.cue:21:10
   152  +      //     ./in.cue:22:5
   153  +      // eliminated.x.n: field not allowed:
   154         //     ./in.cue:23:5
   155         //     ./in.cue:23:16
   156         n: (_|_){
   157           // [eval] eliminated.x.n: field not allowed:
   158  -        //     ./in.cue:21:10
   159  -        //     ./in.cue:22:14
   160           //     ./in.cue:23:5
   161           //     ./in.cue:23:16
   162         }
   163       }
   164       out: (_|_){
   165  -      // [eval] eliminated.x: 2 errors in empty disjunction:
   166  -      // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct):
   167  -      //     ./in.cue:22:5
   168  -      //     ./in.cue:23:14
   169  -      // eliminated.x.n: field not allowed:
   170  -      //     ./in.cue:21:10
   171  -      //     ./in.cue:22:14
   172  +      // [eval] eliminated.x: conflicting values null and {} (mismatched types null and struct):
   173  +      //     ./in.cue:21:10
   174  +      //     ./in.cue:22:5
   175  +      // eliminated.x.n: field not allowed:
   176         //     ./in.cue:23:5
   177         //     ./in.cue:23:16
   178       }
   179  -- diff/todo/p3 --
   180  Small differences in error output. Empty disjunction error.
   181  -- out/eval --
   182  Errors:
   183  eliminated.x: 2 errors in empty disjunction:
   184  eliminated.x: conflicting values null and {n:3} (mismatched types null and struct):
   185      ./in.cue:22:5
   186      ./in.cue:23:14
   187  eliminated.x.n: field not allowed:
   188      ./in.cue:21:10
   189      ./in.cue:22:14
   190      ./in.cue:23:5
   191      ./in.cue:23:16
   192  
   193  Result:
   194  (_|_){
   195    // [eval]
   196    issue3330: (struct){
   197      #A: (#struct){
   198        let empty#1 = (#struct){
   199        }
   200        field: (#struct){
   201          n: (int){ 3 }
   202        }
   203      }
   204      out: (#list){
   205        0: (#struct){
   206          let empty#1 = (#struct){
   207          }
   208          field: (#struct){
   209            n: (int){ 3 }
   210          }
   211        }
   212      }
   213    }
   214    eliminated: (_|_){
   215      // [eval]
   216      #empty: (#struct){
   217      }
   218      x: (_|_){
   219        // [eval] eliminated.x: 2 errors in empty disjunction:
   220        // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct):
   221        //     ./in.cue:22:5
   222        //     ./in.cue:23:14
   223        // eliminated.x.n: field not allowed:
   224        //     ./in.cue:21:10
   225        //     ./in.cue:22:14
   226        //     ./in.cue:23:5
   227        //     ./in.cue:23:16
   228        n: (_|_){
   229          // [eval] eliminated.x.n: field not allowed:
   230          //     ./in.cue:21:10
   231          //     ./in.cue:22:14
   232          //     ./in.cue:23:5
   233          //     ./in.cue:23:16
   234        }
   235      }
   236      out: (_|_){
   237        // [eval] eliminated.x: 2 errors in empty disjunction:
   238        // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct):
   239        //     ./in.cue:22:5
   240        //     ./in.cue:23:14
   241        // eliminated.x.n: field not allowed:
   242        //     ./in.cue:21:10
   243        //     ./in.cue:22:14
   244        //     ./in.cue:23:5
   245        //     ./in.cue:23:16
   246      }
   247    }
   248    simplified: (struct){
   249      #struct: (#struct){
   250        field: (#struct){
   251          n: (int){ 3 }
   252        }
   253        g: (#struct){
   254        }
   255      }
   256      out: (#struct){
   257        field: (#struct){
   258          n: (int){ 3 }
   259        }
   260        g: (#struct){
   261        }
   262      }
   263    }
   264  }
   265  -- out/compile --
   266  --- in.cue
   267  {
   268    issue3330: {
   269      #A: {
   270        let empty#1 = {}
   271        field: (null|{
   272          n: int
   273        })
   274        field: (〈0;let empty#1〉 & {
   275          n: 3
   276        })
   277      }
   278      out: 〈import;list〉.Concat([
   279        [
   280          〈2;#A〉,
   281        ],
   282      ])
   283    }
   284    eliminated: {
   285      #empty: {}
   286      x: (null|{
   287        n: 3
   288      })
   289      x: (〈0;#empty〉 & {
   290        n: 3
   291      })
   292      out: len(〈0;x〉)
   293    }
   294    simplified: {
   295      #struct: {
   296        field: ({
   297          n: 3
   298        } & 〈0;g〉)
   299        g: {}
   300      }
   301      out: (〈0;#struct〉 & {})
   302    }
   303  }