github.com/solo-io/cue@v0.4.7/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  -- out/eval --
    28  Errors:
    29  z.x: field not allowed: f2:
    30      ./in.cue:2:2
    31      ./in.cue:5:12
    32      ./in.cue:11:4
    33      ./in.cue:14:3
    34  
    35  Result:
    36  (_|_){
    37    // [eval]
    38    #T: (#struct){
    39      x: (#struct){
    40        f1: (int){ int }
    41      }
    42    }
    43    z: (_|_){
    44      // [eval]
    45      x: (_|_){
    46        // [eval]
    47        f1: (int){ 99 }
    48        f2: (_|_){
    49          // [eval] z.x: field not allowed: f2:
    50          //     ./in.cue:2:2
    51          //     ./in.cue:5:12
    52          //     ./in.cue:11:4
    53          //     ./in.cue:14:3
    54        }
    55      }
    56    }
    57    t: (#struct){
    58      p: (string){ "foo" }
    59    }
    60    #C: (#struct){
    61      p: (_){ _ }
    62    }
    63  }
    64  -- out/compile --
    65  --- in.cue
    66  {
    67    #T: {
    68      if true {
    69        x: close({
    70          f1: int
    71        })
    72      }
    73      x: _
    74    }
    75    z: (〈0;#T〉 & {
    76      x: {
    77        f1: 99
    78        f2: "i want to disallow this"
    79      }
    80    })
    81    t: 〈0;#C〉
    82    #C: {
    83      if true {
    84        p: _
    85      }
    86    }
    87    t: {
    88      p: "foo"
    89    }
    90  }