...

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

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

     1
     2-- in.cue --
     3// Mixing struct fields and embedded scalars should error. Using comprehensions
     4// this follows a different path which may miss the error.
     5// TODO: fix
     6out: {
     7	for k in keys {
     8		if values[k] != _|_  {
     9			val: k
    10			if val != _|_ {
    11				k
    12			}
    13		}
    14	}
    15}
    16
    17// multiple lets are mapped to the same location and will conflict. This is
    18// fine, though, as lets do not represent a single data field. This should
    19// therefore not error.
    20// TODO: fix
    21multiLets: {
    22	for k in keys {
    23		if values[k] != _|_  {
    24			let val = k
    25			if val != _|_ {
    26				k
    27			}
    28		}
    29	}
    30}
    31
    32keys: [
    33	// order matters
    34	"a",
    35	"b",
    36]
    37
    38values: {
    39	// order does not matter
    40	"b": "member"
    41	"c": "foo"
    42}
    43
    44full: {
    45	out: {
    46
    47		// changing this to a list of the keys "fixes" things, i.e. this comprehension is required
    48		for k, _ in #github_team_membership {
    49	
    50			// Remove this comprehension to trigger a different type of cycle error
    51			if ( values[k] != _|_ ) {
    52	
    53				// This let is also required
    54				let val = values[k]
    55	
    56				if val != null && ((val & string) != _|_) {
    57					(k): val
    58				}
    59			}
    60		}
    61	}
    62
    63	#github_team_membership: {
    64		team_id: string
    65		role:    string
    66	}
    67
    68	values: {
    69		"role":     "member"
    70		"username": "foo"
    71	}
    72}
    73-- out/eval/stats --
    74Leaks:  3
    75Freed:  23
    76Reused: 17
    77Allocs: 9
    78Retain: 58
    79
    80Unifications: 26
    81Conjuncts:    50
    82Disjuncts:    56
    83-- out/evalalpha --
    84Errors:
    85out: cannot combine regular field "val" with "b":
    86    ./in.cue:33:2
    87
    88Result:
    89(_|_){
    90  // [eval]
    91  out: (_|_){
    92    // [eval] out: cannot combine regular field "val" with "b":
    93    //     ./in.cue:33:2
    94    val: (string){ "b" }
    95  }
    96  multiLets: (string){
    97    "b"
    98    let val#1multi = &[&[&[&[&[&[〈2;k〉]]]]]]
    99  }
   100  keys: (#list){
   101    0: (string){ "a" }
   102    1: (string){ "b" }
   103  }
   104  values: (struct){
   105    b: (string){ "member" }
   106    c: (string){ "foo" }
   107  }
   108  full: (struct){
   109    out: (_|_){
   110      // [incomplete] full.out: non-concrete value _ in operand to !=:
   111      //     ./in.cue:54:8
   112      let val#2multi = &[&[&[&[&[&[&[〈4;values〉[〈2;k〉]]]]]]]]
   113    }
   114    #github_team_membership: (#struct){
   115      team_id: (string){ string }
   116      role: (string){ string }
   117    }
   118    values: (struct){
   119      role: (string){ "member" }
   120      username: (string){ "foo" }
   121    }
   122  }
   123}
   124-- diff/-out/evalalpha<==>+out/eval --
   125diff old new
   126--- old
   127+++ new
   128@@ -12,7 +12,7 @@
   129   }
   130   multiLets: (string){
   131     "b"
   132-    let val#1multi = 〈2;k〉
   133+    let val#1multi = &[&[&[&[&[&[〈2;k〉]]]]]]
   134   }
   135   keys: (#list){
   136     0: (string){ "a" }
   137@@ -23,9 +23,10 @@
   138     c: (string){ "foo" }
   139   }
   140   full: (struct){
   141-    out: (struct){
   142-      let val#2multi = 〈4;values〉[〈2;k〉]
   143-      role: (string){ "member" }
   144+    out: (_|_){
   145+      // [incomplete] full.out: non-concrete value _ in operand to !=:
   146+      //     ./in.cue:54:8
   147+      let val#2multi = &[&[&[&[&[&[&[〈4;values〉[〈2;k〉]]]]]]]]
   148     }
   149     #github_team_membership: (#struct){
   150       team_id: (string){ string }
   151-- diff/explanation --
   152Conjunct groups in let output.
   153-- out/eval --
   154Errors:
   155out: cannot combine regular field "val" with "b":
   156    ./in.cue:33:2
   157
   158Result:
   159(_|_){
   160  // [eval]
   161  out: (_|_){
   162    // [eval] out: cannot combine regular field "val" with "b":
   163    //     ./in.cue:33:2
   164    val: (string){ "b" }
   165  }
   166  multiLets: (string){
   167    "b"
   168    let val#1multi = 〈2;k〉
   169  }
   170  keys: (#list){
   171    0: (string){ "a" }
   172    1: (string){ "b" }
   173  }
   174  values: (struct){
   175    b: (string){ "member" }
   176    c: (string){ "foo" }
   177  }
   178  full: (struct){
   179    out: (struct){
   180      let val#2multi = 〈4;values〉[〈2;k〉]
   181      role: (string){ "member" }
   182    }
   183    #github_team_membership: (#struct){
   184      team_id: (string){ string }
   185      role: (string){ string }
   186    }
   187    values: (struct){
   188      role: (string){ "member" }
   189      username: (string){ "foo" }
   190    }
   191  }
   192}
   193-- out/compile --
   194--- in.cue
   195{
   196  out: {
   197    for _, k in 〈1;keys〉 {
   198      if (〈3;values〉[〈1;k〉] != _|_(explicit error (_|_ literal) in source)) {
   199        val: 〈2;k〉
   200        if (〈0;val〉 != _|_(explicit error (_|_ literal) in source)) {
   201          〈3;k〉
   202        }
   203      }
   204    }
   205  }
   206  multiLets: {
   207    for _, k in 〈1;keys〉 {
   208      if (〈3;values〉[〈1;k〉] != _|_(explicit error (_|_ literal) in source)) {
   209        let val#1multi = 〈2;k〉
   210        if (〈0;let val#1〉 != _|_(explicit error (_|_ literal) in source)) {
   211          〈3;k〉
   212        }
   213      }
   214    }
   215  }
   216  keys: [
   217    "a",
   218    "b",
   219  ]
   220  values: {
   221    b: "member"
   222    c: "foo"
   223  }
   224  full: {
   225    out: {
   226      for k, _ in 〈1;#github_team_membership〉 {
   227        if (〈3;values〉[〈1;k〉] != _|_(explicit error (_|_ literal) in source)) {
   228          let val#2multi = 〈4;values〉[〈2;k〉]
   229          if ((〈0;let val#2〉 != null) && ((〈0;let val#2〉 & string) != _|_(explicit error (_|_ literal) in source))) {
   230            〈3;k〉: 〈1;let val#2〉
   231          }
   232        }
   233      }
   234    }
   235    #github_team_membership: {
   236      team_id: string
   237      role: string
   238    }
   239    values: {
   240      role: "member"
   241      username: "foo"
   242    }
   243  }
   244}

View as plain text