-- in.cue --
import (
	"list"
	"strings"
)

a1: {
	a: and([b, c])
	b: =~"oo"
	c: =~"fo"
}
a2: a1 & {a: "foo"}
a3: a1 & {a: "bar"}

o1: {
	a: or([b, c])
	b: string
	c: "bar"
}
o2: o1 & {a: "foo"}
o3: o1 & {a: "foo", b: "baz"}

// Issue #585
stringListErrors: {
	a: {
		x: [string, ...string]
		result: strings.Join(x, " ")
	}

	b: {
		x: [int, ...string]
		result: strings.Join(x, " ")
	}

	c: {
		x: []
		result: strings.Join(x, int)
	}
}

decimalListErrors: {
	a: {
		x: [string]
		result: list.Avg(x)
		// TODO: allow checking wrapped errors: args=[string, number],
	}

	b: {
		x: [int, ...string]
		result: list.Avg(x)
	}
}
-- issue3648.cue --
// Fully finalize values before passing them to builtins.

// "not properly initialized" error regression in evalv3 involving builtins:
// list.Concat received an unfinalized value when called from a pattern constraint.
// https://cuelang.org/issue/3648
import "list"

issue3648: reduced: {
	[string]: {
		a: list.Concat([b])
		b: [{}]
	}
	foo: {}
}
issue3648: full: {
	#Redirect: path?: string

	[string]: {
		// Note that this bug disappears if the order of the fields below is swapped.
		allRedirects: list.Concat([redirects])
		redirects: [...#Redirect]
	}
	foo: {}
}
-- out/compile --
--- in.cue
{
  a1: {
    a: and([
      〈1;b〉,
      〈1;c〉,
    ])
    b: =~"oo"
    c: =~"fo"
  }
  a2: (〈0;a1〉 & {
    a: "foo"
  })
  a3: (〈0;a1〉 & {
    a: "bar"
  })
  o1: {
    a: or([
      〈1;b〉,
      〈1;c〉,
    ])
    b: string
    c: "bar"
  }
  o2: (〈0;o1〉 & {
    a: "foo"
  })
  o3: (〈0;o1〉 & {
    a: "foo"
    b: "baz"
  })
  stringListErrors: {
    a: {
      x: [
        string,
        ...string,
      ]
      result: 〈import;strings〉.Join(〈0;x〉, " ")
    }
    b: {
      x: [
        int,
        ...string,
      ]
      result: 〈import;strings〉.Join(〈0;x〉, " ")
    }
    c: {
      x: []
      result: 〈import;strings〉.Join(〈0;x〉, int)
    }
  }
  decimalListErrors: {
    a: {
      x: [
        string,
      ]
      result: 〈import;list〉.Avg(〈0;x〉)
    }
    b: {
      x: [
        int,
        ...string,
      ]
      result: 〈import;list〉.Avg(〈0;x〉)
    }
  }
}
--- issue3648.cue
{
  issue3648: {
    reduced: {
      [string]: {
        a: 〈import;list〉.Concat([
          〈1;b〉,
        ])
        b: [
          {},
        ]
      }
      foo: {}
    }
  }
  issue3648: {
    full: {
      #Redirect: {
        path?: string
      }
      [string]: {
        allRedirects: 〈import;list〉.Concat([
          〈1;redirects〉,
        ])
        redirects: [
          ...〈2;#Redirect〉,
        ]
      }
      foo: {}
    }
  }
}
