cuelang.org/go@v0.13.0/cue/testdata/comprehensions/issue293.txtar (about)

     1  
     2  -- in.cue --
     3  #T: {
     4  	if true {
     5  		// We'd like to restrict the possible members of x in this case,
     6  		// but this doesn't work.
     7  		x: close({
     8  			f1: int
     9  		})
    10  	}
    11  	x: _
    12  }
    13  z: #T & {
    14  	x: {
    15  		f1: 99
    16  		f2: "i want to disallow this"
    17  	}
    18  }
    19  
    20  t: #C
    21  #C: {
    22  	if true {
    23  		p: _
    24  	}
    25  }
    26  t: p: "foo"
    27  
    28  -- variant1.cue --
    29  #V1: {
    30  	x: close({ f1: int })
    31  	x: f2: 2
    32  }
    33  -- out/eval/stats --
    34  Leaks:  3
    35  Freed:  16
    36  Reused: 12
    37  Allocs: 7
    38  Retain: 4
    39  
    40  Unifications: 19
    41  Conjuncts:    33
    42  Disjuncts:    20
    43  -- out/evalalpha --
    44  Errors:
    45  #V1.x.f2: field not allowed:
    46      ./variant1.cue:3:5
    47  z.x.f2: field not allowed:
    48      ./in.cue:14:3
    49  
    50  Result:
    51  (_|_){
    52    // [eval]
    53    #T: (#struct){
    54      x: (#struct){
    55        f1: (int){ int }
    56      }
    57    }
    58    z: (_|_){
    59      // [eval]
    60      x: (_|_){
    61        // [eval]
    62        f1: (int){ 99 }
    63        f2: (_|_){
    64          // [eval] z.x.f2: field not allowed:
    65          //     ./in.cue:14:3
    66        }
    67      }
    68    }
    69    t: (#struct){
    70      p: (string){ "foo" }
    71    }
    72    #C: (#struct){
    73      p: (_){ _ }
    74    }
    75    #V1: (_|_){
    76      // [eval]
    77      x: (_|_){
    78        // [eval]
    79        f2: (_|_){
    80          // [eval] #V1.x.f2: field not allowed:
    81          //     ./variant1.cue:3:5
    82        }
    83        f1: (int){ int }
    84      }
    85    }
    86  }
    87  -- diff/-out/evalalpha<==>+out/eval --
    88  diff old new
    89  --- old
    90  +++ new
    91  @@ -1,11 +1,7 @@
    92   Errors:
    93   #V1.x.f2: field not allowed:
    94  -    ./variant1.cue:2:11
    95       ./variant1.cue:3:5
    96   z.x.f2: field not allowed:
    97  -    ./in.cue:2:2
    98  -    ./in.cue:5:12
    99  -    ./in.cue:11:4
   100       ./in.cue:14:3
   101   
   102   Result:
   103  @@ -23,9 +19,6 @@
   104         f1: (int){ 99 }
   105         f2: (_|_){
   106           // [eval] z.x.f2: field not allowed:
   107  -        //     ./in.cue:2:2
   108  -        //     ./in.cue:5:12
   109  -        //     ./in.cue:11:4
   110           //     ./in.cue:14:3
   111         }
   112       }
   113  @@ -40,12 +33,11 @@
   114       // [eval]
   115       x: (_|_){
   116         // [eval]
   117  -      f1: (int){ int }
   118         f2: (_|_){
   119           // [eval] #V1.x.f2: field not allowed:
   120  -        //     ./variant1.cue:2:11
   121           //     ./variant1.cue:3:5
   122         }
   123  +      f1: (int){ int }
   124       }
   125     }
   126   }
   127  -- diff/todo/p2 --
   128  Missing positions
   129  -- diff/todo/p3 --
   130  Reordering
   131  -- out/eval --
   132  Errors:
   133  #V1.x.f2: field not allowed:
   134      ./variant1.cue:2:11
   135      ./variant1.cue:3:5
   136  z.x.f2: field not allowed:
   137      ./in.cue:2:2
   138      ./in.cue:5:12
   139      ./in.cue:11:4
   140      ./in.cue:14:3
   141  
   142  Result:
   143  (_|_){
   144    // [eval]
   145    #T: (#struct){
   146      x: (#struct){
   147        f1: (int){ int }
   148      }
   149    }
   150    z: (_|_){
   151      // [eval]
   152      x: (_|_){
   153        // [eval]
   154        f1: (int){ 99 }
   155        f2: (_|_){
   156          // [eval] z.x.f2: field not allowed:
   157          //     ./in.cue:2:2
   158          //     ./in.cue:5:12
   159          //     ./in.cue:11:4
   160          //     ./in.cue:14:3
   161        }
   162      }
   163    }
   164    t: (#struct){
   165      p: (string){ "foo" }
   166    }
   167    #C: (#struct){
   168      p: (_){ _ }
   169    }
   170    #V1: (_|_){
   171      // [eval]
   172      x: (_|_){
   173        // [eval]
   174        f1: (int){ int }
   175        f2: (_|_){
   176          // [eval] #V1.x.f2: field not allowed:
   177          //     ./variant1.cue:2:11
   178          //     ./variant1.cue:3:5
   179        }
   180      }
   181    }
   182  }
   183  -- out/compile --
   184  --- in.cue
   185  {
   186    #T: {
   187      if true {
   188        x: close({
   189          f1: int
   190        })
   191      }
   192      x: _
   193    }
   194    z: (〈0;#T〉 & {
   195      x: {
   196        f1: 99
   197        f2: "i want to disallow this"
   198      }
   199    })
   200    t: 〈0;#C〉
   201    #C: {
   202      if true {
   203        p: _
   204      }
   205    }
   206    t: {
   207      p: "foo"
   208    }
   209  }
   210  --- variant1.cue
   211  {
   212    #V1: {
   213      x: close({
   214        f1: int
   215      })
   216      x: {
   217        f2: 2
   218      }
   219    }
   220  }