cuelang.org/go@v0.13.0/cue/testdata/eval/issue2235.txtar (about)

     1  // Test various orders
     2  // https://cuelang.org/issues/2235
     3  
     4  -- reductions.cue --
     5  // Each of these tests triggers a slightly different path.
     6  
     7  t1: {
     8  	params: x.y
     9  	x: y: {}
    10  	for _ in x {
    11  		if true {
    12  			x: y: a: {}
    13  		}
    14  	}
    15  }
    16  
    17  t2: {
    18  	out: X.y
    19  	let X = m.x
    20  	m: x: y: {}
    21  	for v in m {
    22  		if true {
    23  			m: x: y: z: {}
    24  		}
    25  	}
    26  }
    27  
    28  t3: {
    29  	out: foo.bar
    30  
    31  	foo: bar: {}
    32  
    33  	for _ in foo {
    34  		for name, _ in foo {
    35  			foo: (name): _
    36  		}
    37  	}
    38  }
    39  
    40  -- issue2235.cue --
    41  package kubecluster
    42  
    43  import (
    44  	"strings"
    45  	"net"
    46  )
    47  
    48  shorewallParams: close({
    49  	[=~"^[A-Z0-9_]+$"]: [...net.IP]
    50  })
    51  
    52  #Cluster: {
    53  	clusterName:     string
    54  	shorewallPrefix: "KUBERNETES_\(strings.ToUpper(clusterName))"
    55  }
    56  
    57  clusters: [CLUSTER=string]: #Cluster & {
    58  	clusterName: CLUSTER
    59  }
    60  
    61  #Cluster: {
    62  	globalIngressControllers: [string]: #GlobalIngressController
    63  	globalIngressControllers: admin:    #GlobalIngressController & {
    64  		class: "admin"
    65  	}
    66  	for _, c in globalIngressControllers {
    67  		objects: c.objects
    68  	}
    69  }
    70  
    71  for clusterName, cluster in clusters {
    72  	for class, controller in cluster.globalIngressControllers {
    73  		let svc = controller.objects.namespaced.ingress.Service["\(class)-nginx-ingress-controller"]
    74  
    75  		shorewallParams: "\(cluster.shorewallPrefix)_INGRESS_\(strings.ToUpper(class))": svc.spec.externalIPs
    76  	}
    77  }
    78  
    79  #GlobalIngressController: {
    80  	class: string
    81  
    82  	objects: namespaced: ingress: {
    83  		Service: "\(class)-nginx-ingress-controller": {
    84  			spec: {
    85  				externalIPs: ["127.0.0.1"]
    86  			}
    87  		}
    88  	}
    89  
    90  	for kind, objs in objects.namespaced.ingress {
    91  		for name, obj in objs {
    92  			objects: namespaced: ingress: "\(kind)": "\(name)": metadata: labels: {
    93  				"ingress-class": class
    94  				stack:           "ingress"
    95  				...
    96  			}
    97  		}
    98  	}
    99  }
   100  
   101  clusters: foo: {}
   102  -- out/eval/stats --
   103  Leaks:  20
   104  Freed:  84
   105  Reused: 79
   106  Allocs: 25
   107  Retain: 68
   108  
   109  Unifications: 104
   110  Conjuncts:    271
   111  Disjuncts:    161
   112  -- out/evalalpha --
   113  (struct){
   114    shorewallParams: (#struct){
   115      KUBERNETES_FOO_INGRESS_ADMIN: (#list){
   116        0: (string){ "127.0.0.1" }
   117      }
   118    }
   119    #Cluster: (#struct){
   120      clusterName: (string){ string }
   121      shorewallPrefix: (_|_){
   122        // [incomplete] #Cluster.shorewallPrefix: invalid interpolation: error in call to strings.ToUpper: non-concrete value string:
   123        //     ./issue2235.cue:14:19
   124        //     ./issue2235.cue:13:19
   125        //     ./issue2235.cue:14:33
   126      }
   127      globalIngressControllers: (#struct){
   128        admin: (#struct){
   129          class: (string){ "admin" }
   130          objects: (#struct){
   131            namespaced: (#struct){
   132              ingress: (#struct){
   133                Service: (#struct){
   134                  "admin-nginx-ingress-controller": (#struct){
   135                    spec: (#struct){
   136                      externalIPs: (#list){
   137                        0: (string){ "127.0.0.1" }
   138                      }
   139                    }
   140                    metadata: (#struct){
   141                      labels: (#struct){
   142                        "ingress-class": (string){ "admin" }
   143                        stack: (string){ "ingress" }
   144                      }
   145                    }
   146                  }
   147                }
   148              }
   149            }
   150          }
   151        }
   152      }
   153      objects: ~(#Cluster.globalIngressControllers.admin.objects)
   154    }
   155    clusters: (struct){
   156      foo: (#struct){
   157        clusterName: (string){ "foo" }
   158        shorewallPrefix: (string){ "KUBERNETES_FOO" }
   159        globalIngressControllers: (#struct){
   160          admin: (#struct){
   161            class: (string){ "admin" }
   162            objects: (#struct){
   163              namespaced: (#struct){
   164                ingress: (#struct){
   165                  Service: (#struct){
   166                    "admin-nginx-ingress-controller": (#struct){
   167                      spec: (#struct){
   168                        externalIPs: (#list){
   169                          0: (string){ "127.0.0.1" }
   170                        }
   171                      }
   172                      metadata: (#struct){
   173                        labels: (#struct){
   174                          "ingress-class": (string){ "admin" }
   175                          stack: (string){ "ingress" }
   176                        }
   177                      }
   178                    }
   179                  }
   180                }
   181              }
   182            }
   183          }
   184        }
   185        objects: ~(clusters.foo.globalIngressControllers.admin.objects)
   186      }
   187    }
   188    #GlobalIngressController: (_|_){
   189      // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: key value of dynamic field must be concrete, found _|_(invalid interpolation: #GlobalIngressController.objects.namespaced.ingress.Service: non-concrete value string (type string)):
   190      //     ./issue2235.cue:43:12
   191      class: (string){ string }
   192      objects: (#struct){
   193        namespaced: (#struct){
   194          ingress: (_|_){
   195            // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: key value of dynamic field must be concrete, found _|_(invalid interpolation: #GlobalIngressController.objects.namespaced.ingress.Service: non-concrete value string (type string)):
   196            //     ./issue2235.cue:43:12
   197            Service: (_|_){
   198              // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: key value of dynamic field must be concrete, found _|_(invalid interpolation: #GlobalIngressController.objects.namespaced.ingress.Service: non-concrete value string (type string)):
   199              //     ./issue2235.cue:43:12
   200            }
   201          }
   202        }
   203      }
   204    }
   205    t1: (struct){
   206      params: ~(t1.x.y)
   207      x: (struct){
   208        y: (struct){
   209          a: (struct){
   210          }
   211        }
   212      }
   213    }
   214    t2: (struct){
   215      out: ~(t2.m.x.y)
   216      let X#2 = ~(t2.m.x)
   217      m: (struct){
   218        x: (struct){
   219          y: (struct){
   220            z: (struct){
   221            }
   222          }
   223        }
   224      }
   225    }
   226    t3: (struct){
   227      out: (struct){
   228      }
   229      foo: (struct){
   230        bar: (struct){
   231        }
   232      }
   233    }
   234    let svc#1multi = 〈1;controller〉.objects.namespaced.ingress.Service["\(〈1;class〉)-nginx-ingress-controller"]
   235  }
   236  -- diff/-out/evalalpha<==>+out/eval --
   237  diff old new
   238  --- old
   239  +++ new
   240  @@ -38,27 +38,7 @@
   241           }
   242         }
   243       }
   244  -    objects: (#struct){
   245  -      namespaced: (#struct){
   246  -        ingress: (#struct){
   247  -          Service: (#struct){
   248  -            "admin-nginx-ingress-controller": (#struct){
   249  -              spec: (#struct){
   250  -                externalIPs: (#list){
   251  -                  0: (string){ "127.0.0.1" }
   252  -                }
   253  -              }
   254  -              metadata: (#struct){
   255  -                labels: (#struct){
   256  -                  "ingress-class": (string){ "admin" }
   257  -                  stack: (string){ "ingress" }
   258  -                }
   259  -              }
   260  -            }
   261  -          }
   262  -        }
   263  -      }
   264  -    }
   265  +    objects: ~(#Cluster.globalIngressControllers.admin.objects)
   266     }
   267     clusters: (struct){
   268       foo: (#struct){
   269  @@ -90,44 +70,21 @@
   270             }
   271           }
   272         }
   273  -      objects: (#struct){
   274  -        namespaced: (#struct){
   275  -          ingress: (#struct){
   276  -            Service: (#struct){
   277  -              "admin-nginx-ingress-controller": (#struct){
   278  -                spec: (#struct){
   279  -                  externalIPs: (#list){
   280  -                    0: (string){ "127.0.0.1" }
   281  -                  }
   282  -                }
   283  -                metadata: (#struct){
   284  -                  labels: (#struct){
   285  -                    "ingress-class": (string){ "admin" }
   286  -                    stack: (string){ "ingress" }
   287  -                  }
   288  -                }
   289  -              }
   290  -            }
   291  -          }
   292  -        }
   293  -      }
   294  +      objects: ~(clusters.foo.globalIngressControllers.admin.objects)
   295       }
   296     }
   297     #GlobalIngressController: (_|_){
   298  -    // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: invalid interpolation: non-concrete value string (type string):
   299  +    // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: key value of dynamic field must be concrete, found _|_(invalid interpolation: #GlobalIngressController.objects.namespaced.ingress.Service: non-concrete value string (type string)):
   300       //     ./issue2235.cue:43:12
   301  -    //     ./issue2235.cue:40:9
   302       class: (string){ string }
   303       objects: (#struct){
   304         namespaced: (#struct){
   305           ingress: (_|_){
   306  -          // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: invalid interpolation: non-concrete value string (type string):
   307  +          // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: key value of dynamic field must be concrete, found _|_(invalid interpolation: #GlobalIngressController.objects.namespaced.ingress.Service: non-concrete value string (type string)):
   308             //     ./issue2235.cue:43:12
   309  -          //     ./issue2235.cue:40:9
   310             Service: (_|_){
   311  -            // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: invalid interpolation: non-concrete value string (type string):
   312  +            // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: key value of dynamic field must be concrete, found _|_(invalid interpolation: #GlobalIngressController.objects.namespaced.ingress.Service: non-concrete value string (type string)):
   313               //     ./issue2235.cue:43:12
   314  -            //     ./issue2235.cue:40:9
   315             }
   316           }
   317         }
   318  @@ -134,10 +91,7 @@
   319       }
   320     }
   321     t1: (struct){
   322  -    params: (struct){
   323  -      a: (struct){
   324  -      }
   325  -    }
   326  +    params: ~(t1.x.y)
   327       x: (struct){
   328         y: (struct){
   329           a: (struct){
   330  @@ -146,16 +100,8 @@
   331       }
   332     }
   333     t2: (struct){
   334  -    out: (struct){
   335  -      z: (struct){
   336  -      }
   337  -    }
   338  -    let X#2 = (struct){
   339  -      y: (struct){
   340  -        z: (struct){
   341  -        }
   342  -      }
   343  -    }
   344  +    out: ~(t2.m.x.y)
   345  +    let X#2 = ~(t2.m.x)
   346       m: (struct){
   347         x: (struct){
   348           y: (struct){
   349  -- diff/todo/p2 --
   350  Different, but okay, error message, but missing some positions
   351  -- out/eval --
   352  (struct){
   353    shorewallParams: (#struct){
   354      KUBERNETES_FOO_INGRESS_ADMIN: (#list){
   355        0: (string){ "127.0.0.1" }
   356      }
   357    }
   358    #Cluster: (#struct){
   359      clusterName: (string){ string }
   360      shorewallPrefix: (_|_){
   361        // [incomplete] #Cluster.shorewallPrefix: invalid interpolation: error in call to strings.ToUpper: non-concrete value string:
   362        //     ./issue2235.cue:14:19
   363        //     ./issue2235.cue:13:19
   364        //     ./issue2235.cue:14:33
   365      }
   366      globalIngressControllers: (#struct){
   367        admin: (#struct){
   368          class: (string){ "admin" }
   369          objects: (#struct){
   370            namespaced: (#struct){
   371              ingress: (#struct){
   372                Service: (#struct){
   373                  "admin-nginx-ingress-controller": (#struct){
   374                    spec: (#struct){
   375                      externalIPs: (#list){
   376                        0: (string){ "127.0.0.1" }
   377                      }
   378                    }
   379                    metadata: (#struct){
   380                      labels: (#struct){
   381                        "ingress-class": (string){ "admin" }
   382                        stack: (string){ "ingress" }
   383                      }
   384                    }
   385                  }
   386                }
   387              }
   388            }
   389          }
   390        }
   391      }
   392      objects: (#struct){
   393        namespaced: (#struct){
   394          ingress: (#struct){
   395            Service: (#struct){
   396              "admin-nginx-ingress-controller": (#struct){
   397                spec: (#struct){
   398                  externalIPs: (#list){
   399                    0: (string){ "127.0.0.1" }
   400                  }
   401                }
   402                metadata: (#struct){
   403                  labels: (#struct){
   404                    "ingress-class": (string){ "admin" }
   405                    stack: (string){ "ingress" }
   406                  }
   407                }
   408              }
   409            }
   410          }
   411        }
   412      }
   413    }
   414    clusters: (struct){
   415      foo: (#struct){
   416        clusterName: (string){ "foo" }
   417        shorewallPrefix: (string){ "KUBERNETES_FOO" }
   418        globalIngressControllers: (#struct){
   419          admin: (#struct){
   420            class: (string){ "admin" }
   421            objects: (#struct){
   422              namespaced: (#struct){
   423                ingress: (#struct){
   424                  Service: (#struct){
   425                    "admin-nginx-ingress-controller": (#struct){
   426                      spec: (#struct){
   427                        externalIPs: (#list){
   428                          0: (string){ "127.0.0.1" }
   429                        }
   430                      }
   431                      metadata: (#struct){
   432                        labels: (#struct){
   433                          "ingress-class": (string){ "admin" }
   434                          stack: (string){ "ingress" }
   435                        }
   436                      }
   437                    }
   438                  }
   439                }
   440              }
   441            }
   442          }
   443        }
   444        objects: (#struct){
   445          namespaced: (#struct){
   446            ingress: (#struct){
   447              Service: (#struct){
   448                "admin-nginx-ingress-controller": (#struct){
   449                  spec: (#struct){
   450                    externalIPs: (#list){
   451                      0: (string){ "127.0.0.1" }
   452                    }
   453                  }
   454                  metadata: (#struct){
   455                    labels: (#struct){
   456                      "ingress-class": (string){ "admin" }
   457                      stack: (string){ "ingress" }
   458                    }
   459                  }
   460                }
   461              }
   462            }
   463          }
   464        }
   465      }
   466    }
   467    #GlobalIngressController: (_|_){
   468      // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: invalid interpolation: non-concrete value string (type string):
   469      //     ./issue2235.cue:43:12
   470      //     ./issue2235.cue:40:9
   471      class: (string){ string }
   472      objects: (#struct){
   473        namespaced: (#struct){
   474          ingress: (_|_){
   475            // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: invalid interpolation: non-concrete value string (type string):
   476            //     ./issue2235.cue:43:12
   477            //     ./issue2235.cue:40:9
   478            Service: (_|_){
   479              // [incomplete] #GlobalIngressController.objects.namespaced.ingress.Service: invalid interpolation: non-concrete value string (type string):
   480              //     ./issue2235.cue:43:12
   481              //     ./issue2235.cue:40:9
   482            }
   483          }
   484        }
   485      }
   486    }
   487    t1: (struct){
   488      params: (struct){
   489        a: (struct){
   490        }
   491      }
   492      x: (struct){
   493        y: (struct){
   494          a: (struct){
   495          }
   496        }
   497      }
   498    }
   499    t2: (struct){
   500      out: (struct){
   501        z: (struct){
   502        }
   503      }
   504      let X#2 = (struct){
   505        y: (struct){
   506          z: (struct){
   507          }
   508        }
   509      }
   510      m: (struct){
   511        x: (struct){
   512          y: (struct){
   513            z: (struct){
   514            }
   515          }
   516        }
   517      }
   518    }
   519    t3: (struct){
   520      out: (struct){
   521      }
   522      foo: (struct){
   523        bar: (struct){
   524        }
   525      }
   526    }
   527    let svc#1multi = 〈1;controller〉.objects.namespaced.ingress.Service["\(〈1;class〉)-nginx-ingress-controller"]
   528  }
   529  -- out/compile --
   530  --- issue2235.cue
   531  {
   532    shorewallParams: close({
   533      [=~"^[A-Z0-9_]+$"]: [
   534        ...〈import;net〉.IP,
   535      ]
   536    })
   537    #Cluster: {
   538      clusterName: string
   539      shorewallPrefix: "KUBERNETES_\(〈import;strings〉.ToUpper(〈0;clusterName〉))"
   540    }
   541    clusters: {
   542      [string]: (〈1;#Cluster〉 & {
   543        clusterName: 〈1;-〉
   544      })
   545    }
   546    #Cluster: {
   547      globalIngressControllers: {
   548        [string]: 〈2;#GlobalIngressController〉
   549      }
   550      globalIngressControllers: {
   551        admin: (〈2;#GlobalIngressController〉 & {
   552          class: "admin"
   553        })
   554      }
   555      for _, c in 〈0;globalIngressControllers〉 {
   556        objects: 〈1;c〉.objects
   557      }
   558    }
   559    for clusterName, cluster in 〈0;clusters〉 {
   560      for class, controller in 〈1;cluster〉.globalIngressControllers {
   561        let svc#1multi = 〈1;controller〉.objects.namespaced.ingress.Service["\(〈1;class〉)-nginx-ingress-controller"]
   562        shorewallParams: {
   563          "\(〈4;cluster〉.shorewallPrefix)_INGRESS_\(〈import;strings〉.ToUpper(〈2;class〉))": 〈1;let svc#1〉.spec.externalIPs
   564        }
   565      }
   566    }
   567    #GlobalIngressController: {
   568      class: string
   569      objects: {
   570        namespaced: {
   571          ingress: {
   572            Service: {
   573              "\(〈4;class〉)-nginx-ingress-controller": {
   574                spec: {
   575                  externalIPs: [
   576                    "127.0.0.1",
   577                  ]
   578                }
   579              }
   580            }
   581          }
   582        }
   583      }
   584      for kind, objs in 〈0;objects〉.namespaced.ingress {
   585        for name, obj in 〈1;objs〉 {
   586          objects: {
   587            namespaced: {
   588              ingress: {
   589                "\(〈6;kind〉)": {
   590                  "\(〈5;name〉)": {
   591                    metadata: {
   592                      labels: {
   593                        "ingress-class": 〈11;class〉
   594                        stack: "ingress"
   595                        ...
   596                      }
   597                    }
   598                  }
   599                }
   600              }
   601            }
   602          }
   603        }
   604      }
   605    }
   606    clusters: {
   607      foo: {}
   608    }
   609  }
   610  --- reductions.cue
   611  {
   612    t1: {
   613      params: 〈0;x〉.y
   614      x: {
   615        y: {}
   616      }
   617      for _, _ in 〈0;x〉 {
   618        if true {
   619          x: {
   620            y: {
   621              a: {}
   622            }
   623          }
   624        }
   625      }
   626    }
   627    t2: {
   628      out: 〈0;let X#2〉.y
   629      let X#2 = 〈0;m〉.x
   630      m: {
   631        x: {
   632          y: {}
   633        }
   634      }
   635      for _, v in 〈0;m〉 {
   636        if true {
   637          m: {
   638            x: {
   639              y: {
   640                z: {}
   641              }
   642            }
   643          }
   644        }
   645      }
   646    }
   647    t3: {
   648      out: 〈0;foo〉.bar
   649      foo: {
   650        bar: {}
   651      }
   652      for _, _ in 〈0;foo〉 {
   653        for name, _ in 〈2;foo〉 {
   654          foo: {
   655            〈2;name〉: _
   656          }
   657        }
   658      }
   659    }
   660  }