cuelang.org/go@v0.10.1/cue/testdata/export/issue2244.txtar (about)

     1  -- in.cue --
     2  package x
     3  
     4  import (
     5  	"strings"
     6  )
     7  
     8  _#matchPattern: {
     9  	#pattern: string
    10  	[
    11  		// can't remove this builtin call
    12  		if strings.HasSuffix(#pattern, "*") {
    13  
    14  			// this let is required _within_ the if block
    15  			// i.e. it can't be "inlined" with the if that
    16  			// currently contains it
    17  			let prefix = strings.TrimSuffix(#pattern, "*")
    18  
    19  			prefix
    20  		},
    21  		"'\(#pattern)'",
    22  	][0]
    23  }
    24  
    25  _#isReleaseTag: _#matchPattern & {#pattern: "refs/tags/v*", _}
    26  
    27  #step: {
    28  	if: number | string
    29  }
    30  
    31  m: #step & {
    32  	if: _#isReleaseTag
    33  }
    34  -- out/eval/stats --
    35  Leaks:  16
    36  Freed:  17
    37  Reused: 13
    38  Allocs: 20
    39  Retain: 30
    40  
    41  Unifications: 24
    42  Conjuncts:    58
    43  Disjuncts:    40
    44  -- diff/explanation --
    45  New evaluator should ultimately disallow new definitions in closed structs
    46  and not allow #pattern in #step
    47  -- out/eval --
    48  (struct){
    49    _#matchPattern(:x): (_|_){
    50      // [incomplete] _#matchPattern: error in call to strings.HasSuffix: non-concrete value string:
    51      //     ./in.cue:11:6
    52      //     ./in.cue:8:12
    53      #pattern: (string){ string }
    54    }
    55    _#isReleaseTag(:x): (string){
    56      "refs/tags/v"
    57      #pattern: (string){ "refs/tags/v*" }
    58      let prefix#1 = (string){ "refs/tags/v" }
    59    }
    60    #step: (#struct){
    61      if: ((string|number)){ |((number){ number }, (string){ string }) }
    62    }
    63    m: (#struct){
    64      if: (string){
    65        "refs/tags/v"
    66        #pattern: (string){ "refs/tags/v*" }
    67        let prefix#1 = (string){ "refs/tags/v" }
    68      }
    69    }
    70  }
    71  -- out/compile --
    72  --- in.cue
    73  {
    74    _#matchPattern: {
    75      #pattern: string
    76      [
    77        if 〈import;strings〉.HasSuffix(〈1;#pattern〉, "*") {
    78          let prefix#1 = 〈import;strings〉.TrimSuffix(〈2;#pattern〉, "*")
    79          〈0;let prefix#1〉
    80        },
    81        "'\(〈1;#pattern〉)'",
    82      ][0]
    83    }
    84    _#isReleaseTag: (〈0;_#matchPattern〉 & {
    85      #pattern: "refs/tags/v*"
    86      _
    87    })
    88    #step: {
    89      if: (number|string)
    90    }
    91    m: (〈0;#step〉 & {
    92      if: 〈1;_#isReleaseTag〉
    93    })
    94  }