-- in.cue --
import (
	"encoding/yaml"
	"regexp"
)

simplified: {
	x: d: R={
		".*"
		[R+""][0]
	}
	out: yaml.Marshal(x)
}

original: {
	#testableRegexp: R={
		string

		#test: close({
			in:  string
			out: regexp.FindSubmatch("^"+R+"$", in)[1]
		})
	}

	rule: {
		#patterns: {
			bar: #testableRegexp & {
				"(.*)"
				#test: {in: "testcontent", out: "testcontent"}
			}
		}
	}
	out: yaml.Marshal(rule)
}
-- out/eval/stats --
Leaks:  4
Freed:  17
Reused: 10
Allocs: 11
Retain: 4

Unifications: 21
Conjuncts:    39
Disjuncts:    21
-- out/eval --
(struct){
  simplified: (struct){
    x: (struct){
      d: (string){ ".*" }
    }
    out: (string){ "d: .*\n" }
  }
  original: (struct){
    #testableRegexp: (string){
      string
      #test: (#struct){
        in: (string){ string }
        out: (_|_){
          // [incomplete] original.#testableRegexp.#test.out: non-concrete value string in operand to +:
          //     ./in.cue:20:29
          //     ./in.cue:15:21
          //     ./in.cue:16:3
        }
      }
    }
    rule: (struct){
      #patterns: (#struct){
        bar: (string){
          "(.*)"
          #test: (#struct){
            in: (string){ "testcontent" }
            out: (string){ "testcontent" }
          }
        }
      }
    }
    out: (string){ "{}\n" }
  }
}
-- out/compile --
--- in.cue
{
  simplified: {
    x: {
      d: {
        ".*"
        [
          (〈2〉 + ""),
        ][0]
      }
    }
    out: 〈import;"encoding/yaml"〉.Marshal(〈0;x〉)
  }
  original: {
    #testableRegexp: {
      string
      #test: close({
        in: string
        out: 〈import;regexp〉.FindSubmatch((("^" + 〈2〉) + "$"), 〈0;in〉)[1]
      })
    }
    rule: {
      #patterns: {
        bar: (〈2;#testableRegexp〉 & {
          "(.*)"
          #test: {
            in: "testcontent"
            out: "testcontent"
          }
        })
      }
    }
    out: 〈import;"encoding/yaml"〉.Marshal(〈0;rule〉)
  }
}
