cuelang.org/go@v0.10.1/cue/testdata/comprehensions/closed.txtar (about)

     1  -- in.cue --
     2  dynamicTop: {
     3  	#D: {
     4  		for k, v in {foo: 123} {(k): v}
     5  	}
     6  }
     7  
     8  // Issue #1404
     9  dynamicDepth1: {
    10  	#D: {
    11  		a: foo: 123
    12  		b: {for k, v in a {(k): v}}
    13  	}
    14  }
    15  
    16  allowed: {
    17  	#D: {
    18  		if true {
    19  			d: int
    20  		}
    21  	}
    22  
    23  	vErr: #D & {d: 5}
    24  }
    25  
    26  disallowed: {
    27  	#D: {
    28  		if false {
    29  			d: int
    30  		}
    31  	}
    32  
    33  	vErr: #D & {d: 5}
    34  }
    35  
    36  // Interpret comprehensions as embeddings.
    37  // Issue #1956
    38  comprehensionIsEmbed: {
    39  	#A: size: int | *1
    40  	#B: {
    41  		kind: string
    42  
    43  		// Should be identical to just #A. That is, #A is treated as open.
    44  		if true {
    45  			#A
    46  		}
    47  	}
    48  	x: #B & {
    49  		kind: "A"
    50  	}
    51  }
    52  
    53  // This comprehension is inside a definition and should still disallow b.
    54  noEraseDefinition: {
    55  	#Foo: [if true {a: int}]
    56  	a: { #Foo & [{ b: 2 }] } // Error
    57  }
    58  
    59  issue1956: {
    60  	#Details: {
    61  		size: int | *1
    62  	}
    63  
    64  	#Thing: {
    65  		kind: "KindA" | "KindB"
    66  		if kind == "KindA" {
    67  			#Details
    68  		}
    69  	}
    70  
    71  	x: #Thing & {
    72  		kind: "KindA"
    73  	}
    74  }
    75  
    76  // This triggers adding the same "closedInfo" twice, potentially causing
    77  // a cyclic linked list in the todo list.
    78  dedupTodo: {
    79  	#sub: {
    80  		c: _
    81  		if c.n == "c" {
    82  			X: test: c
    83  		}
    84  	}
    85  
    86  	out: #sub // needs to be definition
    87  	out: {
    88  		c: n: "c" // Do not combine with &, as the original issue relies on this.
    89  		c: n: string
    90  	}
    91  }
    92  
    93  -- out/eval/stats --
    94  Leaks:  2
    95  Freed:  70
    96  Reused: 64
    97  Allocs: 8
    98  Retain: 3
    99  
   100  Unifications: 58
   101  Conjuncts:    103
   102  Disjuncts:    71
   103  -- out/evalalpha --
   104  Errors:
   105  noEraseDefinition.a.0.b: field not allowed:
   106      ./in.cue:55:17
   107  disallowed.vErr.d: field not allowed:
   108      ./in.cue:28:7
   109      ./in.cue:28:4
   110      ./in.cue:32:14
   111  
   112  Result:
   113  (_|_){
   114    // [eval]
   115    dynamicTop: (struct){
   116      #D: (#struct){
   117        foo: (int){ 123 }
   118      }
   119    }
   120    dynamicDepth1: (struct){
   121      #D: (#struct){
   122        a: (#struct){
   123          foo: (int){ 123 }
   124        }
   125        b: (#struct){
   126          foo: (int){ 123 }
   127        }
   128      }
   129    }
   130    allowed: (struct){
   131      #D: (#struct){
   132        d: (int){ int }
   133      }
   134      vErr: (#struct){
   135        d: (int){ 5 }
   136      }
   137    }
   138    disallowed: (_|_){
   139      // [eval]
   140      #D: (#struct){
   141      }
   142      vErr: (_|_){
   143        // [eval]
   144        d: (_|_){
   145          // [eval] disallowed.vErr.d: field not allowed:
   146          //     ./in.cue:28:7
   147          //     ./in.cue:28:4
   148          //     ./in.cue:32:14
   149        }
   150      }
   151    }
   152    comprehensionIsEmbed: (struct){
   153      #A: (#struct){
   154        size: (int){ |(*(int){ 1 }, (int){ int }) }
   155      }
   156      #B: (#struct){
   157        kind: (string){ string }
   158        size: (int){ |(*(int){ 1 }, (int){ int }) }
   159      }
   160      x: (#struct){
   161        kind: (string){ "A" }
   162        size: (int){ |(*(int){ 1 }, (int){ int }) }
   163      }
   164    }
   165    noEraseDefinition: (_|_){
   166      // [eval]
   167      #Foo: (#list){
   168        0: (#struct){
   169          a: (int){ int }
   170        }
   171      }
   172      a: (_|_){
   173        // [eval]
   174        0: (_|_){
   175          // [eval]
   176          b: (_|_){
   177            // [eval] noEraseDefinition.a.0.b: field not allowed:
   178            //     ./in.cue:55:17
   179          }
   180          a: (int){ int }
   181        }
   182      }
   183    }
   184    issue1956: (struct){
   185      #Details: (#struct){
   186        size: (int){ |(*(int){ 1 }, (int){ int }) }
   187      }
   188      #Thing: (_|_){
   189        // [incomplete] issue1956.#Thing: unresolved disjunction "KindA" | "KindB" (type string):
   190        //     ./in.cue:65:6
   191        kind: (string){ |((string){ "KindA" }, (string){ "KindB" }) }
   192      }
   193      x: (#struct){
   194        kind: (string){ "KindA" }
   195        size: (int){ |(*(int){ 1 }, (int){ int }) }
   196      }
   197    }
   198    dedupTodo: (struct){
   199      #sub: (_|_){
   200        // [incomplete] dedupTodo.#sub: c.n undefined as c is incomplete (type _):
   201        //     ./in.cue:80:6
   202        c: (_){ _ }
   203      }
   204      out: (#struct){
   205        c: (#struct){
   206          n: (string){ "c" }
   207        }
   208        X: (#struct){
   209          test: (#struct){
   210            n: (string){ "c" }
   211          }
   212        }
   213      }
   214    }
   215  }
   216  -- diff/-out/evalalpha<==>+out/eval --
   217  diff old new
   218  --- old
   219  +++ new
   220  @@ -1,15 +1,10 @@
   221   Errors:
   222  +noEraseDefinition.a.0.b: field not allowed:
   223  +    ./in.cue:55:17
   224   disallowed.vErr.d: field not allowed:
   225  -    ./in.cue:26:6
   226  -    ./in.cue:27:3
   227  -    ./in.cue:27:12
   228  +    ./in.cue:28:7
   229       ./in.cue:28:4
   230  -    ./in.cue:32:8
   231       ./in.cue:32:14
   232  -noEraseDefinition.a.0.b: field not allowed:
   233  -    ./in.cue:54:17
   234  -    ./in.cue:55:7
   235  -    ./in.cue:55:17
   236   
   237   Result:
   238   (_|_){
   239  @@ -45,11 +40,8 @@
   240         // [eval]
   241         d: (_|_){
   242           // [eval] disallowed.vErr.d: field not allowed:
   243  -        //     ./in.cue:26:6
   244  -        //     ./in.cue:27:3
   245  -        //     ./in.cue:27:12
   246  +        //     ./in.cue:28:7
   247           //     ./in.cue:28:4
   248  -        //     ./in.cue:32:8
   249           //     ./in.cue:32:14
   250         }
   251       }
   252  @@ -78,13 +70,11 @@
   253         // [eval]
   254         0: (_|_){
   255           // [eval]
   256  -        a: (int){ int }
   257           b: (_|_){
   258             // [eval] noEraseDefinition.a.0.b: field not allowed:
   259  -          //     ./in.cue:54:17
   260  -          //     ./in.cue:55:7
   261             //     ./in.cue:55:17
   262           }
   263  +        a: (int){ int }
   264         }
   265       }
   266     }
   267  @@ -109,7 +99,7 @@
   268         c: (_){ _ }
   269       }
   270       out: (#struct){
   271  -      c: (struct){
   272  +      c: (#struct){
   273           n: (string){ "c" }
   274         }
   275         X: (#struct){
   276  -- diff/todo/p3 --
   277  Missing error positions.
   278  -- diff/explanation --
   279  dedupTodo.out: the new evaluator correctly marks this as closed.
   280  -- out/eval --
   281  Errors:
   282  disallowed.vErr.d: field not allowed:
   283      ./in.cue:26:6
   284      ./in.cue:27:3
   285      ./in.cue:27:12
   286      ./in.cue:28:4
   287      ./in.cue:32:8
   288      ./in.cue:32:14
   289  noEraseDefinition.a.0.b: field not allowed:
   290      ./in.cue:54:17
   291      ./in.cue:55:7
   292      ./in.cue:55:17
   293  
   294  Result:
   295  (_|_){
   296    // [eval]
   297    dynamicTop: (struct){
   298      #D: (#struct){
   299        foo: (int){ 123 }
   300      }
   301    }
   302    dynamicDepth1: (struct){
   303      #D: (#struct){
   304        a: (#struct){
   305          foo: (int){ 123 }
   306        }
   307        b: (#struct){
   308          foo: (int){ 123 }
   309        }
   310      }
   311    }
   312    allowed: (struct){
   313      #D: (#struct){
   314        d: (int){ int }
   315      }
   316      vErr: (#struct){
   317        d: (int){ 5 }
   318      }
   319    }
   320    disallowed: (_|_){
   321      // [eval]
   322      #D: (#struct){
   323      }
   324      vErr: (_|_){
   325        // [eval]
   326        d: (_|_){
   327          // [eval] disallowed.vErr.d: field not allowed:
   328          //     ./in.cue:26:6
   329          //     ./in.cue:27:3
   330          //     ./in.cue:27:12
   331          //     ./in.cue:28:4
   332          //     ./in.cue:32:8
   333          //     ./in.cue:32:14
   334        }
   335      }
   336    }
   337    comprehensionIsEmbed: (struct){
   338      #A: (#struct){
   339        size: (int){ |(*(int){ 1 }, (int){ int }) }
   340      }
   341      #B: (#struct){
   342        kind: (string){ string }
   343        size: (int){ |(*(int){ 1 }, (int){ int }) }
   344      }
   345      x: (#struct){
   346        kind: (string){ "A" }
   347        size: (int){ |(*(int){ 1 }, (int){ int }) }
   348      }
   349    }
   350    noEraseDefinition: (_|_){
   351      // [eval]
   352      #Foo: (#list){
   353        0: (#struct){
   354          a: (int){ int }
   355        }
   356      }
   357      a: (_|_){
   358        // [eval]
   359        0: (_|_){
   360          // [eval]
   361          a: (int){ int }
   362          b: (_|_){
   363            // [eval] noEraseDefinition.a.0.b: field not allowed:
   364            //     ./in.cue:54:17
   365            //     ./in.cue:55:7
   366            //     ./in.cue:55:17
   367          }
   368        }
   369      }
   370    }
   371    issue1956: (struct){
   372      #Details: (#struct){
   373        size: (int){ |(*(int){ 1 }, (int){ int }) }
   374      }
   375      #Thing: (_|_){
   376        // [incomplete] issue1956.#Thing: unresolved disjunction "KindA" | "KindB" (type string):
   377        //     ./in.cue:65:6
   378        kind: (string){ |((string){ "KindA" }, (string){ "KindB" }) }
   379      }
   380      x: (#struct){
   381        kind: (string){ "KindA" }
   382        size: (int){ |(*(int){ 1 }, (int){ int }) }
   383      }
   384    }
   385    dedupTodo: (struct){
   386      #sub: (_|_){
   387        // [incomplete] dedupTodo.#sub: c.n undefined as c is incomplete (type _):
   388        //     ./in.cue:80:6
   389        c: (_){ _ }
   390      }
   391      out: (#struct){
   392        c: (struct){
   393          n: (string){ "c" }
   394        }
   395        X: (#struct){
   396          test: (#struct){
   397            n: (string){ "c" }
   398          }
   399        }
   400      }
   401    }
   402  }
   403  -- out/compile --
   404  --- in.cue
   405  {
   406    dynamicTop: {
   407      #D: {
   408        for k, v in {
   409          foo: 123
   410        } {
   411          〈1;k〉: 〈1;v〉
   412        }
   413      }
   414    }
   415    dynamicDepth1: {
   416      #D: {
   417        a: {
   418          foo: 123
   419        }
   420        b: {
   421          for k, v in 〈1;a〉 {
   422            〈1;k〉: 〈1;v〉
   423          }
   424        }
   425      }
   426    }
   427    allowed: {
   428      #D: {
   429        if true {
   430          d: int
   431        }
   432      }
   433      vErr: (〈0;#D〉 & {
   434        d: 5
   435      })
   436    }
   437    disallowed: {
   438      #D: {
   439        if false {
   440          d: int
   441        }
   442      }
   443      vErr: (〈0;#D〉 & {
   444        d: 5
   445      })
   446    }
   447    comprehensionIsEmbed: {
   448      #A: {
   449        size: (int|*1)
   450      }
   451      #B: {
   452        kind: string
   453        if true {
   454          〈2;#A〉
   455        }
   456      }
   457      x: (〈0;#B〉 & {
   458        kind: "A"
   459      })
   460    }
   461    noEraseDefinition: {
   462      #Foo: [
   463        if true {
   464          a: int
   465        },
   466      ]
   467      a: {
   468        (〈1;#Foo〉 & [
   469          {
   470            b: 2
   471          },
   472        ])
   473      }
   474    }
   475    issue1956: {
   476      #Details: {
   477        size: (int|*1)
   478      }
   479      #Thing: {
   480        kind: ("KindA"|"KindB")
   481        if (〈0;kind〉 == "KindA") {
   482          〈2;#Details〉
   483        }
   484      }
   485      x: (〈0;#Thing〉 & {
   486        kind: "KindA"
   487      })
   488    }
   489    dedupTodo: {
   490      #sub: {
   491        c: _
   492        if (〈0;c〉.n == "c") {
   493          X: {
   494            test: 〈2;c〉
   495          }
   496        }
   497      }
   498      out: 〈0;#sub〉
   499      out: {
   500        c: {
   501          n: "c"
   502        }
   503        c: {
   504          n: string
   505        }
   506      }
   507    }
   508  }