github.com/solo-io/cue@v0.4.7/cue/testdata/cycle/compbottom2.txtar (about)

     1  -- in.cue --
     2  
     3  self: {
     4      fail: {
     5          a: {
     6              if a.b == _|_ {
     7                  b: 1
     8              }
     9          }
    10      }
    11      isConcreteFail: {
    12          a: {
    13              if a.b == _|_ {
    14                  b: 1
    15              }
    16              b: int
    17          }
    18      }
    19      isNotConcrete: {
    20          a: {
    21              if a.b != _|_ {
    22                  b: 1
    23              }
    24              b: int
    25          }
    26      }
    27  }
    28  
    29  mutual: {
    30  	noConflicts: {
    31  		a: { if b.foo == _|_ { new: "" } }
    32  		b: { if a.bar == _|_ { new: "" } }
    33  	}
    34  
    35  	mutualCycleFail: {
    36  		b: { if a.bar == _|_ { foo: "" } }
    37  		a: { if b.foo == _|_ { bar: "" } }
    38  	}
    39  
    40      brokenCycleSuccess: {
    41  		a: { if b.foo == _|_ { foo: "" } }
    42  		b: { if a.bar == _|_ { bar: "" } }
    43          a: bar: ""
    44  	}
    45  
    46  	oneDirectionalConflictFail: {
    47          p1: {
    48              a: { if b.foo == _|_ { bar: "" } }
    49              b: { if a.bar == _|_ { new: "" } }
    50          }
    51          p2: {
    52              a: { if b.foo == _|_ { new: "" } }
    53              b: { if a.bar == _|_ { foo: "" } }
    54          }
    55  	}
    56  
    57  	oneDirectionalBrokenConflictSuccess: {
    58  		a: { if b.foo == _|_ { bar: "" } }
    59  		b: { if a.bar == _|_ { new: "" } }
    60          b: foo: ""
    61  	}
    62  }
    63  
    64  sameStruct: {
    65  	chainSuccess: {
    66  		raises?: {}
    67  		if raises == _|_ {
    68  			ret: a: 1
    69  		}
    70  		ret?: {}
    71  		if ret != _|_ {
    72  			foo: a: 1
    73  		}
    74  	}
    75  
    76  	cycleFail: {
    77  		raises?: {}
    78  		if raises == _|_ {
    79  			ret: a: 1
    80  		}
    81  		ret?: {}
    82  		if ret != _|_ {
    83  			raises: a: 1
    84  		}
    85  	}
    86  
    87  	defCloseSuccess: {
    88  		#Example: {
    89  			raises?: {
    90  				runtime?:     string
    91  			}
    92  		
    93  			if raises == _|_ {
    94  				ret?: _
    95  			}
    96  		}
    97  
    98  		expr: #Example & {
    99  		   ret: 2
   100  		}
   101  	}
   102  }
   103  
   104  // Issue
   105  nestedChain: {
   106  	cycleFail: {
   107  		if #E.x != _|_ {
   108  			#E: y: true
   109  		}
   110  		if #E.y == _|_ {
   111  			#E: x: true
   112  		}
   113  		#E: [_]: bool
   114  	}
   115  
   116  	brokenCycleSuccess: {
   117  		if #E.x != _|_ {
   118  			#E: y: true
   119  		}
   120  		if #E.y == _|_ {
   121  			#E: x: true
   122  		}
   123  		#E: [_]: bool
   124  		#E: x: true
   125  	}
   126  
   127    // TODO: the current algorithm does _not_ handle checking fields that were
   128    // not added in certain situations.
   129  	doubleAddfail: {
   130  		if #E.x == _|_ {
   131  			#E: y: true
   132  		}
   133  		if #E.y == _|_ {
   134  			#E: x: true
   135  		}
   136  		#E: [_]: bool
   137  	}
   138  
   139  	trippleSuccess: {
   140  		if #E.x != _|_ {
   141  			#E: y: true
   142  		}
   143  		if #E.y != _|_ {
   144  			z: true
   145  		}
   146  		#E: x: true
   147  	}
   148  }
   149  -- out/eval --
   150  Errors:
   151  mutual.mutualCycleFail.a: cycle: field inserted by if clause that was previously evaluated by another if clause: bar
   152  mutual.oneDirectionalConflictFail.p1.a: cycle: field inserted by if clause that was previously evaluated by another if clause: bar
   153  mutual.oneDirectionalConflictFail.p2.b: cycle: field inserted by if clause that was previously evaluated by another if clause: foo
   154  nestedChain.cycleFail.#E: cycle: field inserted by if clause that was previously evaluated by another if clause: x
   155  sameStruct.cycleFail: cycle: field inserted by if clause that was previously evaluated by another if clause: raises
   156  self.fail.a: cycle: field inserted by if clause that was previously evaluated by another if clause: b
   157  
   158  Result:
   159  (_|_){
   160    // [eval]
   161    self: (_|_){
   162      // [eval]
   163      fail: (_|_){
   164        // [eval]
   165        a: (_|_){
   166          // [eval] self.fail.a: cycle: field inserted by if clause that was previously evaluated by another if clause: b
   167          b: (int){ 1 }
   168        }
   169      }
   170      isConcreteFail: (struct){
   171        a: (struct){
   172          b: (int){ 1 }
   173        }
   174      }
   175      isNotConcrete: (struct){
   176        a: (struct){
   177          b: (int){ int }
   178        }
   179      }
   180    }
   181    mutual: (_|_){
   182      // [eval]
   183      noConflicts: (struct){
   184        a: (struct){
   185          new: (string){ "" }
   186        }
   187        b: (struct){
   188          new: (string){ "" }
   189        }
   190      }
   191      mutualCycleFail: (_|_){
   192        // [eval]
   193        b: (struct){
   194        }
   195        a: (_|_){
   196          // [eval] mutual.mutualCycleFail.a: cycle: field inserted by if clause that was previously evaluated by another if clause: bar
   197          bar: (string){ "" }
   198        }
   199      }
   200      brokenCycleSuccess: (struct){
   201        a: (struct){
   202          bar: (string){ "" }
   203          foo: (string){ "" }
   204        }
   205        b: (struct){
   206        }
   207      }
   208      oneDirectionalConflictFail: (_|_){
   209        // [eval]
   210        p1: (_|_){
   211          // [eval]
   212          a: (_|_){
   213            // [eval] mutual.oneDirectionalConflictFail.p1.a: cycle: field inserted by if clause that was previously evaluated by another if clause: bar
   214            bar: (string){ "" }
   215          }
   216          b: (struct){
   217            new: (string){ "" }
   218          }
   219        }
   220        p2: (_|_){
   221          // [eval]
   222          a: (struct){
   223          }
   224          b: (_|_){
   225            // [eval] mutual.oneDirectionalConflictFail.p2.b: cycle: field inserted by if clause that was previously evaluated by another if clause: foo
   226            foo: (string){ "" }
   227          }
   228        }
   229      }
   230      oneDirectionalBrokenConflictSuccess: (struct){
   231        a: (struct){
   232        }
   233        b: (struct){
   234          foo: (string){ "" }
   235          new: (string){ "" }
   236        }
   237      }
   238    }
   239    sameStruct: (_|_){
   240      // [eval]
   241      chainSuccess: (struct){
   242        ret: (struct){
   243          a: (int){ 1 }
   244        }
   245        foo: (struct){
   246          a: (int){ 1 }
   247        }
   248      }
   249      cycleFail: (_|_){
   250        // [eval] sameStruct.cycleFail: cycle: field inserted by if clause that was previously evaluated by another if clause: raises
   251        ret: (struct){
   252          a: (int){ 1 }
   253        }
   254        raises: (struct){
   255          a: (int){ 1 }
   256        }
   257      }
   258      defCloseSuccess: (struct){
   259        #Example: (#struct){
   260        }
   261        expr: (#struct){
   262          ret: (int){ 2 }
   263        }
   264      }
   265    }
   266    nestedChain: (_|_){
   267      // [eval]
   268      cycleFail: (_|_){
   269        // [eval]
   270        #E: (_|_){
   271          // [eval] nestedChain.cycleFail.#E: cycle: field inserted by if clause that was previously evaluated by another if clause: x
   272          x: (bool){ true }
   273        }
   274      }
   275      brokenCycleSuccess: (struct){
   276        #E: (#struct){
   277          x: (bool){ true }
   278          y: (bool){ true }
   279        }
   280      }
   281      doubleAddfail: (struct){
   282        #E: (#struct){
   283          y: (bool){ true }
   284        }
   285      }
   286      trippleSuccess: (struct){
   287        #E: (#struct){
   288          x: (bool){ true }
   289          y: (bool){ true }
   290        }
   291        z: (bool){ true }
   292      }
   293    }
   294  }
   295  -- out/compile --
   296  --- in.cue
   297  {
   298    self: {
   299      fail: {
   300        a: {
   301          if (〈1;a〉.b == _|_(explicit error (_|_ literal) in source)) {
   302            b: 1
   303          }
   304        }
   305      }
   306      isConcreteFail: {
   307        a: {
   308          if (〈1;a〉.b == _|_(explicit error (_|_ literal) in source)) {
   309            b: 1
   310          }
   311          b: int
   312        }
   313      }
   314      isNotConcrete: {
   315        a: {
   316          if (〈1;a〉.b != _|_(explicit error (_|_ literal) in source)) {
   317            b: 1
   318          }
   319          b: int
   320        }
   321      }
   322    }
   323    mutual: {
   324      noConflicts: {
   325        a: {
   326          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
   327            new: ""
   328          }
   329        }
   330        b: {
   331          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
   332            new: ""
   333          }
   334        }
   335      }
   336      mutualCycleFail: {
   337        b: {
   338          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
   339            foo: ""
   340          }
   341        }
   342        a: {
   343          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
   344            bar: ""
   345          }
   346        }
   347      }
   348      brokenCycleSuccess: {
   349        a: {
   350          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
   351            foo: ""
   352          }
   353        }
   354        b: {
   355          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
   356            bar: ""
   357          }
   358        }
   359        a: {
   360          bar: ""
   361        }
   362      }
   363      oneDirectionalConflictFail: {
   364        p1: {
   365          a: {
   366            if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
   367              bar: ""
   368            }
   369          }
   370          b: {
   371            if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
   372              new: ""
   373            }
   374          }
   375        }
   376        p2: {
   377          a: {
   378            if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
   379              new: ""
   380            }
   381          }
   382          b: {
   383            if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
   384              foo: ""
   385            }
   386          }
   387        }
   388      }
   389      oneDirectionalBrokenConflictSuccess: {
   390        a: {
   391          if (〈1;b〉.foo == _|_(explicit error (_|_ literal) in source)) {
   392            bar: ""
   393          }
   394        }
   395        b: {
   396          if (〈1;a〉.bar == _|_(explicit error (_|_ literal) in source)) {
   397            new: ""
   398          }
   399        }
   400        b: {
   401          foo: ""
   402        }
   403      }
   404    }
   405    sameStruct: {
   406      chainSuccess: {
   407        raises?: {}
   408        if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
   409          ret: {
   410            a: 1
   411          }
   412        }
   413        ret?: {}
   414        if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
   415          foo: {
   416            a: 1
   417          }
   418        }
   419      }
   420      cycleFail: {
   421        raises?: {}
   422        if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
   423          ret: {
   424            a: 1
   425          }
   426        }
   427        ret?: {}
   428        if (〈0;ret〉 != _|_(explicit error (_|_ literal) in source)) {
   429          raises: {
   430            a: 1
   431          }
   432        }
   433      }
   434      defCloseSuccess: {
   435        #Example: {
   436          raises?: {
   437            runtime?: string
   438          }
   439          if (〈0;raises〉 == _|_(explicit error (_|_ literal) in source)) {
   440            ret?: _
   441          }
   442        }
   443        expr: (〈0;#Example〉 & {
   444          ret: 2
   445        })
   446      }
   447    }
   448    nestedChain: {
   449      cycleFail: {
   450        if (〈0;#E〉.x != _|_(explicit error (_|_ literal) in source)) {
   451          #E: {
   452            y: true
   453          }
   454        }
   455        if (〈0;#E〉.y == _|_(explicit error (_|_ literal) in source)) {
   456          #E: {
   457            x: true
   458          }
   459        }
   460        #E: {
   461          [_]: bool
   462        }
   463      }
   464      brokenCycleSuccess: {
   465        if (〈0;#E〉.x != _|_(explicit error (_|_ literal) in source)) {
   466          #E: {
   467            y: true
   468          }
   469        }
   470        if (〈0;#E〉.y == _|_(explicit error (_|_ literal) in source)) {
   471          #E: {
   472            x: true
   473          }
   474        }
   475        #E: {
   476          [_]: bool
   477        }
   478        #E: {
   479          x: true
   480        }
   481      }
   482      doubleAddfail: {
   483        if (〈0;#E〉.x == _|_(explicit error (_|_ literal) in source)) {
   484          #E: {
   485            y: true
   486          }
   487        }
   488        if (〈0;#E〉.y == _|_(explicit error (_|_ literal) in source)) {
   489          #E: {
   490            x: true
   491          }
   492        }
   493        #E: {
   494          [_]: bool
   495        }
   496      }
   497      trippleSuccess: {
   498        if (〈0;#E〉.x != _|_(explicit error (_|_ literal) in source)) {
   499          #E: {
   500            y: true
   501          }
   502        }
   503        if (〈0;#E〉.y != _|_(explicit error (_|_ literal) in source)) {
   504          z: true
   505        }
   506        #E: {
   507          x: true
   508        }
   509      }
   510    }
   511  }