github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/eval/closedness.txtar (about)

     1  // Issue #852
     2  
     3  -- in.cue --
     4  #E: {
     5  	c: int
     6  }
     7  #A: {
     8  	b: int
     9  	q: {
    10  		#E
    11  		d: int
    12  	}
    13  }
    14  a: #A & {
    15  	b: 3
    16  	q: {
    17  		c: 2
    18  		e: 43
    19  	}
    20  }
    21  
    22  // `a` is evaluated through the comprehension first. Ensure that
    23  // this does not bypass closedness checks.
    24  issue852: {
    25  	#A: {
    26  		[=~"^a-z$"]: string
    27  	}
    28  
    29  	a: #A
    30  
    31  	a: Foo: "foo"
    32  
    33  	for k, v in a {
    34  		b: "\(k)": v
    35  	}
    36  }
    37  
    38  dynamic: {
    39  	#D: {
    40  		key:   "foo"
    41  		(key): int
    42  	}
    43  	d: #D & {foo: 3}
    44  }
    45  -- out/eval --
    46  Errors:
    47  a.q: field not allowed: e:
    48      ./in.cue:1:5
    49      ./in.cue:6:5
    50      ./in.cue:7:3
    51      ./in.cue:11:4
    52      ./in.cue:15:3
    53  issue852.a: field not allowed: Foo:
    54      ./in.cue:30:14
    55      ./in.cue:22:6
    56      ./in.cue:26:5
    57      ./in.cue:28:5
    58  
    59  Result:
    60  (_|_){
    61    // [eval]
    62    #E: (#struct){
    63      c: (int){ int }
    64    }
    65    #A: (#struct){
    66      b: (int){ int }
    67      q: (#struct){
    68        c: (int){ int }
    69        d: (int){ int }
    70      }
    71    }
    72    a: (_|_){
    73      // [eval]
    74      b: (int){ 3 }
    75      q: (_|_){
    76        // [eval]
    77        c: (int){ 2 }
    78        d: (int){ int }
    79        e: (_|_){
    80          // [eval] a.q: field not allowed: e:
    81          //     ./in.cue:1:5
    82          //     ./in.cue:6:5
    83          //     ./in.cue:7:3
    84          //     ./in.cue:11:4
    85          //     ./in.cue:15:3
    86        }
    87      }
    88    }
    89    issue852: (_|_){
    90      // [eval] issue852.a: field not allowed: Foo:
    91      //     ./in.cue:30:14
    92      //     ./in.cue:22:6
    93      //     ./in.cue:26:5
    94      //     ./in.cue:28:5
    95      #A: (#struct){
    96      }
    97      a: (_|_){
    98        // [eval]
    99        Foo: (_|_){
   100          // [eval] issue852.a: field not allowed: Foo:
   101          //     ./in.cue:30:14
   102          //     ./in.cue:22:6
   103          //     ./in.cue:26:5
   104          //     ./in.cue:28:5
   105        }
   106      }
   107    }
   108    dynamic: (struct){
   109      #D: (#struct){
   110        key: (string){ "foo" }
   111        foo: (int){ int }
   112      }
   113      d: (#struct){
   114        key: (string){ "foo" }
   115        foo: (int){ 3 }
   116      }
   117    }
   118  }
   119  -- out/compile --
   120  --- in.cue
   121  {
   122    #E: {
   123      c: int
   124    }
   125    #A: {
   126      b: int
   127      q: {
   128        〈2;#E〉
   129        d: int
   130      }
   131    }
   132    a: (〈0;#A〉 & {
   133      b: 3
   134      q: {
   135        c: 2
   136        e: 43
   137      }
   138    })
   139    issue852: {
   140      #A: {
   141        [=~"^a-z$"]: string
   142      }
   143      a: 〈0;#A〉
   144      a: {
   145        Foo: "foo"
   146      }
   147      for k, v in 〈0;a〉 {
   148        b: {
   149          "\(〈2;k〉)": 〈2;v〉
   150        }
   151      }
   152    }
   153    dynamic: {
   154      #D: {
   155        key: "foo"
   156        〈0;key〉: int
   157      }
   158      d: (〈0;#D〉 & {
   159        foo: 3
   160      })
   161    }
   162  }