...

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

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

     1-- in.cue --
     2dynamicTop: {
     3	#D: {
     4		for k, v in {foo: 123} {(k): v}
     5	}
     6}
     7
     8// Issue #1404
     9dynamicDepth1: {
    10	#D: {
    11		a: foo: 123
    12		b: {for k, v in a {(k): v}}
    13	}
    14}
    15
    16allowed: {
    17	#D: {
    18		if true {
    19			d: int
    20		}
    21	}
    22
    23	vErr: #D & {d: 5}
    24}
    25
    26disallowed: {
    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
    38comprehensionIsEmbed: {
    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.
    54noEraseDefinition: {
    55	#Foo: [if true {a: int}]
    56	a: { #Foo & [{ b: 2 }] } // Error
    57}
    58
    59issue1956: {
    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.
    78dedupTodo: {
    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 --
    94Leaks:  2
    95Freed:  70
    96Reused: 64
    97Allocs: 8
    98Retain: 3
    99
   100Unifications: 58
   101Conjuncts:    103
   102Disjuncts:    71
   103-- out/eval --
   104Errors:
   105disallowed.vErr.d: field not allowed:
   106    ./in.cue:26:6
   107    ./in.cue:27:3
   108    ./in.cue:27:12
   109    ./in.cue:28:4
   110    ./in.cue:32:8
   111    ./in.cue:32:14
   112noEraseDefinition.a.0.b: field not allowed:
   113    ./in.cue:54:17
   114    ./in.cue:55:7
   115    ./in.cue:55:17
   116
   117Result:
   118(_|_){
   119  // [eval]
   120  dynamicTop: (struct){
   121    #D: (#struct){
   122      foo: (int){ 123 }
   123    }
   124  }
   125  dynamicDepth1: (struct){
   126    #D: (#struct){
   127      a: (#struct){
   128        foo: (int){ 123 }
   129      }
   130      b: (#struct){
   131        foo: (int){ 123 }
   132      }
   133    }
   134  }
   135  allowed: (struct){
   136    #D: (#struct){
   137      d: (int){ int }
   138    }
   139    vErr: (#struct){
   140      d: (int){ 5 }
   141    }
   142  }
   143  disallowed: (_|_){
   144    // [eval]
   145    #D: (#struct){
   146    }
   147    vErr: (_|_){
   148      // [eval]
   149      d: (_|_){
   150        // [eval] disallowed.vErr.d: field not allowed:
   151        //     ./in.cue:26:6
   152        //     ./in.cue:27:3
   153        //     ./in.cue:27:12
   154        //     ./in.cue:28:4
   155        //     ./in.cue:32:8
   156        //     ./in.cue:32:14
   157      }
   158    }
   159  }
   160  comprehensionIsEmbed: (struct){
   161    #A: (#struct){
   162      size: (int){ |(*(int){ 1 }, (int){ int }) }
   163    }
   164    #B: (#struct){
   165      kind: (string){ string }
   166      size: (int){ |(*(int){ 1 }, (int){ int }) }
   167    }
   168    x: (#struct){
   169      kind: (string){ "A" }
   170      size: (int){ |(*(int){ 1 }, (int){ int }) }
   171    }
   172  }
   173  noEraseDefinition: (_|_){
   174    // [eval]
   175    #Foo: (#list){
   176      0: (#struct){
   177        a: (int){ int }
   178      }
   179    }
   180    a: (_|_){
   181      // [eval]
   182      0: (_|_){
   183        // [eval]
   184        a: (int){ int }
   185        b: (_|_){
   186          // [eval] noEraseDefinition.a.0.b: field not allowed:
   187          //     ./in.cue:54:17
   188          //     ./in.cue:55:7
   189          //     ./in.cue:55:17
   190        }
   191      }
   192    }
   193  }
   194  issue1956: (struct){
   195    #Details: (#struct){
   196      size: (int){ |(*(int){ 1 }, (int){ int }) }
   197    }
   198    #Thing: (_|_){
   199      // [incomplete] issue1956.#Thing: unresolved disjunction "KindA" | "KindB" (type string):
   200      //     ./in.cue:65:6
   201      kind: (string){ |((string){ "KindA" }, (string){ "KindB" }) }
   202    }
   203    x: (#struct){
   204      kind: (string){ "KindA" }
   205      size: (int){ |(*(int){ 1 }, (int){ int }) }
   206    }
   207  }
   208  dedupTodo: (struct){
   209    #sub: (_|_){
   210      // [incomplete] dedupTodo.#sub: c.n undefined as c is incomplete (type _):
   211      //     ./in.cue:80:6
   212      c: (_){ _ }
   213    }
   214    out: (#struct){
   215      c: (struct){
   216        n: (string){ "c" }
   217      }
   218      X: (#struct){
   219        test: (#struct){
   220          n: (string){ "c" }
   221        }
   222      }
   223    }
   224  }
   225}
   226-- out/compile --
   227--- in.cue
   228{
   229  dynamicTop: {
   230    #D: {
   231      for k, v in {
   232        foo: 123
   233      } {
   234        〈1;k〉: 〈1;v〉
   235      }
   236    }
   237  }
   238  dynamicDepth1: {
   239    #D: {
   240      a: {
   241        foo: 123
   242      }
   243      b: {
   244        for k, v in 〈1;a〉 {
   245          〈1;k〉: 〈1;v〉
   246        }
   247      }
   248    }
   249  }
   250  allowed: {
   251    #D: {
   252      if true {
   253        d: int
   254      }
   255    }
   256    vErr: (〈0;#D〉 & {
   257      d: 5
   258    })
   259  }
   260  disallowed: {
   261    #D: {
   262      if false {
   263        d: int
   264      }
   265    }
   266    vErr: (〈0;#D〉 & {
   267      d: 5
   268    })
   269  }
   270  comprehensionIsEmbed: {
   271    #A: {
   272      size: (int|*1)
   273    }
   274    #B: {
   275      kind: string
   276      if true {
   277        〈2;#A〉
   278      }
   279    }
   280    x: (〈0;#B〉 & {
   281      kind: "A"
   282    })
   283  }
   284  noEraseDefinition: {
   285    #Foo: [
   286      if true {
   287        a: int
   288      },
   289    ]
   290    a: {
   291      (〈1;#Foo〉 & [
   292        {
   293          b: 2
   294        },
   295      ])
   296    }
   297  }
   298  issue1956: {
   299    #Details: {
   300      size: (int|*1)
   301    }
   302    #Thing: {
   303      kind: ("KindA"|"KindB")
   304      if (〈0;kind〉 == "KindA") {
   305        〈2;#Details〉
   306      }
   307    }
   308    x: (〈0;#Thing〉 & {
   309      kind: "KindA"
   310    })
   311  }
   312  dedupTodo: {
   313    #sub: {
   314      c: _
   315      if (〈0;c〉.n == "c") {
   316        X: {
   317          test: 〈2;c〉
   318        }
   319      }
   320    }
   321    out: 〈0;#sub〉
   322    out: {
   323      c: {
   324        n: "c"
   325      }
   326      c: {
   327        n: string
   328      }
   329    }
   330  }
   331}

View as plain text