cuelang.org/go@v0.13.0/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  -- v3issues.cue --
    94  issue3483: {
    95  	#Schema: schemaField: int
    96  	out1: out2: #Schema & {
    97  		if false {
    98  			schemaField: 3
    99  		}
   100  	}
   101  }
   102  issue3486: {
   103  	#schema: {}
   104  
   105  	if true {
   106  		out: {
   107  			#schema
   108  			// This field should be allowed as #schema is embedded.
   109  			extra: "foo"
   110  		}
   111  	}
   112  }
   113  -- out/eval/stats --
   114  Leaks:  4
   115  Freed:  78
   116  Reused: 74
   117  Allocs: 8
   118  Retain: 3
   119  
   120  Unifications: 68
   121  Conjuncts:    118
   122  Disjuncts:    81
   123  -- out/evalalpha --
   124  Errors:
   125  disallowed.vErr.d: field not allowed:
   126      ./in.cue:28:4
   127      ./in.cue:32:14
   128  noEraseDefinition.a.0.b: field not allowed:
   129      ./in.cue:55:17
   130  
   131  Result:
   132  (_|_){
   133    // [eval]
   134    dynamicTop: (struct){
   135      #D: (#struct){
   136        foo: (int){ 123 }
   137      }
   138    }
   139    dynamicDepth1: (struct){
   140      #D: (#struct){
   141        a: (#struct){
   142          foo: (int){ 123 }
   143        }
   144        b: (#struct){
   145          foo: (int){ 123 }
   146        }
   147      }
   148    }
   149    allowed: (struct){
   150      #D: (#struct){
   151        d: (int){ int }
   152      }
   153      vErr: (#struct){
   154        d: (int){ 5 }
   155      }
   156    }
   157    disallowed: (_|_){
   158      // [eval]
   159      #D: (#struct){
   160      }
   161      vErr: (_|_){
   162        // [eval]
   163        d: (_|_){
   164          // [eval] disallowed.vErr.d: field not allowed:
   165          //     ./in.cue:28:4
   166          //     ./in.cue:32:14
   167        }
   168      }
   169    }
   170    comprehensionIsEmbed: (struct){
   171      #A: (#struct){
   172        size: (int){ |(*(int){ 1 }, (int){ int }) }
   173      }
   174      #B: (#struct){
   175        kind: (string){ string }
   176        size: (int){ |(*(int){ 1 }, (int){ int }) }
   177      }
   178      x: (#struct){
   179        kind: (string){ "A" }
   180        size: (int){ |(*(int){ 1 }, (int){ int }) }
   181      }
   182    }
   183    noEraseDefinition: (_|_){
   184      // [eval]
   185      #Foo: (#list){
   186        0: (#struct){
   187          a: (int){ int }
   188        }
   189      }
   190      a: (_|_){
   191        // [eval]
   192        0: (_|_){
   193          // [eval]
   194          b: (_|_){
   195            // [eval] noEraseDefinition.a.0.b: field not allowed:
   196            //     ./in.cue:55:17
   197          }
   198          a: (int){ int }
   199        }
   200      }
   201    }
   202    issue1956: (struct){
   203      #Details: (#struct){
   204        size: (int){ |(*(int){ 1 }, (int){ int }) }
   205      }
   206      #Thing: (_|_){
   207        // [incomplete] issue1956.#Thing: unresolved disjunction "KindA" | "KindB" (type string):
   208        //     ./in.cue:65:6
   209        kind: (string){ |((string){ "KindA" }, (string){ "KindB" }) }
   210      }
   211      x: (#struct){
   212        kind: (string){ "KindA" }
   213        size: (int){ |(*(int){ 1 }, (int){ int }) }
   214      }
   215    }
   216    dedupTodo: (struct){
   217      #sub: (_|_){
   218        // [incomplete] dedupTodo.#sub: c.n undefined as c is incomplete (type _):
   219        //     ./in.cue:80:6
   220        c: (_){ _ }
   221      }
   222      out: (#struct){
   223        c: (#struct){
   224          n: (string){ "c" }
   225        }
   226        X: (#struct){
   227          test: ~(dedupTodo.out.c)
   228        }
   229      }
   230    }
   231    issue3483: (struct){
   232      #Schema: (#struct){
   233        schemaField: (int){ int }
   234      }
   235      out1: (struct){
   236        out2: (#struct){
   237          schemaField: (int){ int }
   238        }
   239      }
   240    }
   241    issue3486: (struct){
   242      #schema: (#struct){
   243      }
   244      out: (#struct){
   245        extra: (string){ "foo" }
   246      }
   247    }
   248  }
   249  -- diff/-out/evalalpha<==>+out/eval --
   250  diff old new
   251  --- old
   252  +++ new
   253  @@ -1,19 +1,8 @@
   254   Errors:
   255   disallowed.vErr.d: field not allowed:
   256  -    ./in.cue:26:6
   257  -    ./in.cue:27:3
   258  -    ./in.cue:27:12
   259       ./in.cue:28:4
   260  -    ./in.cue:32:8
   261       ./in.cue:32:14
   262  -issue3486.out.extra: field not allowed:
   263  -    ./v3issues.cue:10:11
   264  -    ./v3issues.cue:12:2
   265  -    ./v3issues.cue:14:4
   266  -    ./v3issues.cue:16:4
   267   noEraseDefinition.a.0.b: field not allowed:
   268  -    ./in.cue:54:17
   269  -    ./in.cue:55:7
   270       ./in.cue:55:17
   271   
   272   Result:
   273  @@ -50,11 +39,7 @@
   274         // [eval]
   275         d: (_|_){
   276           // [eval] disallowed.vErr.d: field not allowed:
   277  -        //     ./in.cue:26:6
   278  -        //     ./in.cue:27:3
   279  -        //     ./in.cue:27:12
   280           //     ./in.cue:28:4
   281  -        //     ./in.cue:32:8
   282           //     ./in.cue:32:14
   283         }
   284       }
   285  @@ -83,13 +68,11 @@
   286         // [eval]
   287         0: (_|_){
   288           // [eval]
   289  -        a: (int){ int }
   290           b: (_|_){
   291             // [eval] noEraseDefinition.a.0.b: field not allowed:
   292  -          //     ./in.cue:54:17
   293  -          //     ./in.cue:55:7
   294             //     ./in.cue:55:17
   295           }
   296  +        a: (int){ int }
   297         }
   298       }
   299     }
   300  @@ -114,13 +97,11 @@
   301         c: (_){ _ }
   302       }
   303       out: (#struct){
   304  -      c: (struct){
   305  +      c: (#struct){
   306           n: (string){ "c" }
   307         }
   308         X: (#struct){
   309  -        test: (#struct){
   310  -          n: (string){ "c" }
   311  -        }
   312  +        test: ~(dedupTodo.out.c)
   313         }
   314       }
   315     }
   316  @@ -134,19 +115,11 @@
   317         }
   318       }
   319     }
   320  -  issue3486: (_|_){
   321  -    // [eval]
   322  +  issue3486: (struct){
   323       #schema: (#struct){
   324       }
   325  -    out: (_|_){
   326  -      // [eval]
   327  -      extra: (_|_){
   328  -        // [eval] issue3486.out.extra: field not allowed:
   329  -        //     ./v3issues.cue:10:11
   330  -        //     ./v3issues.cue:12:2
   331  -        //     ./v3issues.cue:14:4
   332  -        //     ./v3issues.cue:16:4
   333  -      }
   334  +    out: (#struct){
   335  +      extra: (string){ "foo" }
   336       }
   337     }
   338   }
   339  -- diff/todo/p3 --
   340  Missing error positions.
   341  -- diff/explanation --
   342  dedupTodo.out.c: the new evaluator correctly marks this as closed.
   343  -- out/eval --
   344  Errors:
   345  disallowed.vErr.d: field not allowed:
   346      ./in.cue:26:6
   347      ./in.cue:27:3
   348      ./in.cue:27:12
   349      ./in.cue:28:4
   350      ./in.cue:32:8
   351      ./in.cue:32:14
   352  issue3486.out.extra: field not allowed:
   353      ./v3issues.cue:10:11
   354      ./v3issues.cue:12:2
   355      ./v3issues.cue:14:4
   356      ./v3issues.cue:16:4
   357  noEraseDefinition.a.0.b: field not allowed:
   358      ./in.cue:54:17
   359      ./in.cue:55:7
   360      ./in.cue:55:17
   361  
   362  Result:
   363  (_|_){
   364    // [eval]
   365    dynamicTop: (struct){
   366      #D: (#struct){
   367        foo: (int){ 123 }
   368      }
   369    }
   370    dynamicDepth1: (struct){
   371      #D: (#struct){
   372        a: (#struct){
   373          foo: (int){ 123 }
   374        }
   375        b: (#struct){
   376          foo: (int){ 123 }
   377        }
   378      }
   379    }
   380    allowed: (struct){
   381      #D: (#struct){
   382        d: (int){ int }
   383      }
   384      vErr: (#struct){
   385        d: (int){ 5 }
   386      }
   387    }
   388    disallowed: (_|_){
   389      // [eval]
   390      #D: (#struct){
   391      }
   392      vErr: (_|_){
   393        // [eval]
   394        d: (_|_){
   395          // [eval] disallowed.vErr.d: field not allowed:
   396          //     ./in.cue:26:6
   397          //     ./in.cue:27:3
   398          //     ./in.cue:27:12
   399          //     ./in.cue:28:4
   400          //     ./in.cue:32:8
   401          //     ./in.cue:32:14
   402        }
   403      }
   404    }
   405    comprehensionIsEmbed: (struct){
   406      #A: (#struct){
   407        size: (int){ |(*(int){ 1 }, (int){ int }) }
   408      }
   409      #B: (#struct){
   410        kind: (string){ string }
   411        size: (int){ |(*(int){ 1 }, (int){ int }) }
   412      }
   413      x: (#struct){
   414        kind: (string){ "A" }
   415        size: (int){ |(*(int){ 1 }, (int){ int }) }
   416      }
   417    }
   418    noEraseDefinition: (_|_){
   419      // [eval]
   420      #Foo: (#list){
   421        0: (#struct){
   422          a: (int){ int }
   423        }
   424      }
   425      a: (_|_){
   426        // [eval]
   427        0: (_|_){
   428          // [eval]
   429          a: (int){ int }
   430          b: (_|_){
   431            // [eval] noEraseDefinition.a.0.b: field not allowed:
   432            //     ./in.cue:54:17
   433            //     ./in.cue:55:7
   434            //     ./in.cue:55:17
   435          }
   436        }
   437      }
   438    }
   439    issue1956: (struct){
   440      #Details: (#struct){
   441        size: (int){ |(*(int){ 1 }, (int){ int }) }
   442      }
   443      #Thing: (_|_){
   444        // [incomplete] issue1956.#Thing: unresolved disjunction "KindA" | "KindB" (type string):
   445        //     ./in.cue:65:6
   446        kind: (string){ |((string){ "KindA" }, (string){ "KindB" }) }
   447      }
   448      x: (#struct){
   449        kind: (string){ "KindA" }
   450        size: (int){ |(*(int){ 1 }, (int){ int }) }
   451      }
   452    }
   453    dedupTodo: (struct){
   454      #sub: (_|_){
   455        // [incomplete] dedupTodo.#sub: c.n undefined as c is incomplete (type _):
   456        //     ./in.cue:80:6
   457        c: (_){ _ }
   458      }
   459      out: (#struct){
   460        c: (struct){
   461          n: (string){ "c" }
   462        }
   463        X: (#struct){
   464          test: (#struct){
   465            n: (string){ "c" }
   466          }
   467        }
   468      }
   469    }
   470    issue3483: (struct){
   471      #Schema: (#struct){
   472        schemaField: (int){ int }
   473      }
   474      out1: (struct){
   475        out2: (#struct){
   476          schemaField: (int){ int }
   477        }
   478      }
   479    }
   480    issue3486: (_|_){
   481      // [eval]
   482      #schema: (#struct){
   483      }
   484      out: (_|_){
   485        // [eval]
   486        extra: (_|_){
   487          // [eval] issue3486.out.extra: field not allowed:
   488          //     ./v3issues.cue:10:11
   489          //     ./v3issues.cue:12:2
   490          //     ./v3issues.cue:14:4
   491          //     ./v3issues.cue:16:4
   492        }
   493      }
   494    }
   495  }
   496  -- out/compile --
   497  --- in.cue
   498  {
   499    dynamicTop: {
   500      #D: {
   501        for k, v in {
   502          foo: 123
   503        } {
   504          〈1;k〉: 〈1;v〉
   505        }
   506      }
   507    }
   508    dynamicDepth1: {
   509      #D: {
   510        a: {
   511          foo: 123
   512        }
   513        b: {
   514          for k, v in 〈1;a〉 {
   515            〈1;k〉: 〈1;v〉
   516          }
   517        }
   518      }
   519    }
   520    allowed: {
   521      #D: {
   522        if true {
   523          d: int
   524        }
   525      }
   526      vErr: (〈0;#D〉 & {
   527        d: 5
   528      })
   529    }
   530    disallowed: {
   531      #D: {
   532        if false {
   533          d: int
   534        }
   535      }
   536      vErr: (〈0;#D〉 & {
   537        d: 5
   538      })
   539    }
   540    comprehensionIsEmbed: {
   541      #A: {
   542        size: (int|*1)
   543      }
   544      #B: {
   545        kind: string
   546        if true {
   547          〈2;#A〉
   548        }
   549      }
   550      x: (〈0;#B〉 & {
   551        kind: "A"
   552      })
   553    }
   554    noEraseDefinition: {
   555      #Foo: [
   556        if true {
   557          a: int
   558        },
   559      ]
   560      a: {
   561        (〈1;#Foo〉 & [
   562          {
   563            b: 2
   564          },
   565        ])
   566      }
   567    }
   568    issue1956: {
   569      #Details: {
   570        size: (int|*1)
   571      }
   572      #Thing: {
   573        kind: ("KindA"|"KindB")
   574        if (〈0;kind〉 == "KindA") {
   575          〈2;#Details〉
   576        }
   577      }
   578      x: (〈0;#Thing〉 & {
   579        kind: "KindA"
   580      })
   581    }
   582    dedupTodo: {
   583      #sub: {
   584        c: _
   585        if (〈0;c〉.n == "c") {
   586          X: {
   587            test: 〈2;c〉
   588          }
   589        }
   590      }
   591      out: 〈0;#sub〉
   592      out: {
   593        c: {
   594          n: "c"
   595        }
   596        c: {
   597          n: string
   598        }
   599      }
   600    }
   601  }
   602  --- v3issues.cue
   603  {
   604    issue3483: {
   605      #Schema: {
   606        schemaField: int
   607      }
   608      out1: {
   609        out2: (〈1;#Schema〉 & {
   610          if false {
   611            schemaField: 3
   612          }
   613        })
   614      }
   615    }
   616    issue3486: {
   617      #schema: {}
   618      if true {
   619        out: {
   620          〈2;#schema〉
   621          extra: "foo"
   622        }
   623      }
   624    }
   625  }