github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/cycle/compbottom2.txtar (about)

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