...

Text file src/cuelang.org/go/cue/testdata/comprehensions/issue293.txtar

Documentation: cuelang.org/go/cue/testdata/comprehensions

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

View as plain text