-- in.cue --
embed: simple: {
	#A: b: 1
	a: {#A}
	a: err: 1
}
embed: andInStruct: {
	#Foo: a: int
	a: {#Foo & {err: 2}}
}
embed: embedDefWithEmbedding: {
	#Foo: {{a: int}}
	a: {#Foo & {err: 2}} // not allowed
}
embed: embedComprehension: {
	#Foo: {if true {a: int}}
	a: {#Foo & {err: 2}} // not allowed
}
embed: fieldWithAnd: {
	#A: {}
	{a: #A & {err: 3}}
}
embed: embedAndRecursive: {
	#A: a: int
	B: x:  #A
	B & {x: err: 2}
}
embed: andEmbed: {
	#A: b: int
	#B: b: int
	#D: {#A & #B}
	d: #D & {err: 3}
}
and: transitive: ok: {
	Z: {a: string}
	#Y: Z
	#X: #Y & Z
	out: #X & {
		a: "foo"
	}
}
and: transitive: err: {
	Z: a: string
	#Y: Z
	#X: #Y & Z
	out: #X & {
		err: "foo"
	}
}
and: transitiveWithEmbed: ok: {
	Z: a: string
	#X: #Y & Z
	#Y: {Z}
	out: #X & {
		a: "foo"
	}
}
and: transitiveWithEmbed: err: {
	Z: a: string
	#X: #Y & Z
	#Y: {Z}
	out: #X & {
		err: "foo"
	}
}
embed: nonDef: t1: {
	X: a: string
	#Y: #Z & X
	#Z: {
		X
		b?: string
	}
}
embed: defAndHidden: full: {
	_stepCommon: Name: string
	#Step: #Command & _stepCommon
	#Command: {
		_stepCommon
		Path?: string
	}
	out: #Step & {
		Name: "foo"
	}
}
embed: withIndirect: {
	A: #B
	#B: b: int
	A & {err: 2} // not allowed
}
-- validators.cue --
import (
	"struct"
	"list"
)

embed: normalValidator: {
	#X: {
		struct.MaxFields(1)
		a?: int
		b?: int
	}
	x: #X
	x: err: 1
}
embed: openValidator: t1: {
	#X: {
		matchN(0, [])
		a?: int
		b?: int
	}
	x: #X
	x: err: 1
}
embed: openValidator: t2: {
	Y: matchN(1, [X])
	X: b?: Y
	a: X
	a: b: 1
}
disjunction: withErr: t1: {
	params: {}
	out: #Schema1 & {
		b1: b2: b3: params.mayExistLater
	}
	#Schema1: b1?: null | #Schema2
	#Schema2: b2?: null | {b3?: string}
}
embed: nestedValidator: {
	#types: z?: list.UniqueItems
	x: y: z: [1]
	x: {
		#def
		y?: #types
	}
	#def: {}
}
-- inline.cue --
embedInline: {
	#Schema: {
		a: "hello"
		// do not close outer struct of 'b', as inlined value is not a schema.
		b: {{x: c: "foo"}.x}
		b: {
			c: string
			d: "never printed"
		}
	}
	out: #Schema & __no_sharing
}
// evalv3 "field not allowed" regression involving embeddings and selectors;
// accessing a field via selector on an embedded definition should stay open.
// https://cuelang.org/issue/3853
issue3853: {
	#Schema: {
		a: "hello"
		// do not close outer struct of 'b', as inlined value is not a schema.
		b: {{x: c: "foo"}.x}
		b: {
			c: string
			d: "never printed"
		}
	}
	out: {x: (#Schema & {}).a}.x
}
-- disjunction.cue --
import "list"

// evalv3 regression: closedness errors no longer reported when default values
// are present; disallowed fields in a default disjunct should still be caught.
// https://cuelang.org/issue/3947
issue3947: full: {
	#Schema: allowed?:     string
	_defaults: disallowed: _ | *"default value"
	out: #Schema & _defaults
}
// evalv3 regression: #oneOf pattern disjunction; unifying a closed definition
// disjunction with a default string field caused incorrect field-not-allowed errors.
// https://cuelang.org/issue/3957
issue3957: reduced: {
	c: a: "bar"
	c: #B & {a: string | *"foo"}
	#B: b?: string
}
issue3957: full: {
	#oneof: {a: string} | {b?: [...string]}
	c: #oneof & {a: string | *"foo"}
	c: a: "bar"
}
issue3957: derived: t1: {
	#Schema: {
		in: string | [...string]
		out: list.FlattenN([in], 1)
	}
	x: #Schema & {in: "foo"}
}
issue3957: derived: t2: {
	#Schema: {
		in: string | [...string]
		let _flat = list.FlattenN([in], 1)
		out: _flat
	}
	out: #Schema & {in: "foo"}
}
-- issue3833.cue --
// evalv3 "field not allowed" regression with embeddings; combining a definition
// that has an open field with another definition via embedding should be allowed.
// https://cuelang.org/issue/3833
issue3833: ok: {
	out: {#A & {a: #B}}
	#A: {
		a: {b: string, ...}
		...
	}
	#C: c: string
	#B: {
		#C & {c: "foo"}
		b: "foo"
	}
}
issue3833: evalv2Issue: {
	out: {#A & {a: #B}}
	#A: {
		a: b: string
		...
	}
	#C: c: string
	#B: {
		#C & {c: "foo"}
		b: "foo"
	}
}
-- issue3837.cue --
// evalv3 regression with embeddings, disjunctions, and extra fields; a struct
// that embeds a definition and adds extra fields should not cause spurious errors.
// https://cuelang.org/issue/3837
issue3837: reduced: {
	A: {
		#Embed
		extra: "foo"
	}
	out: {{x: A & __no_sharing}}
	#Embed: {}
}
issue3837: full: {
	#Embed: {}
	#A: {
		#Embed
		extra: "foo"
	}
	#B: (#C | {})
	#C: bar: string
	out: #B & {
		bar: "baz"
		{
			#def: (#A & __no_sharing)
		}
	}
}
-- issue3832.cue --
// evalv3 "field not allowed" regression with a disjunction and a let field;
// a let binding inside a disjunct should not cause closedness errors.
// https://cuelang.org/issue/3832
issue3832: {
	_person: self: firstName: "Sam"

	#T: {
		_subject: {
			in: _
			out: {
				let self = in.self
				outFirstName: self.firstName
			}
		}
		_assert: pass: _
		_assert: {
			check!: _
			pass:   "never"
		} | {
			invoke!: _
			// TODO: here, the let from _subject.out gets converted to a
			// permanent error,instead of incomplete.
			pass: (_subject & {in: invoke}).out
		}
		results: _assert.pass
	}
	#T & {
		_assert: invoke: _person
	}
}
-- issue3839.cue --
// evalv3 closedness regression with embeddings and definitions; embedding a
// definition with an ellipsis inside a non-definition should remain open.
// https://cuelang.org/issue/3839
issue3839: reduced: {
	x: {A & __no_sharing}
	x: y: 1
	#B: {}
	A: {
		#B
		...
	}
}
issue3839: full: {
	_globals: glb: globalField: ""

	#GlobalContext: globalField: string
	#Context: {
		glb: #GlobalContext
		out: glb
	}
	out: {
		ingress: {
			#Ingress & {
				#def: (#Context & _globals).out
			}
		}

		ingress?: {
			foo: 1234
			bar: "http"
		}
	}
	#Embed: #def: {...}

	#Ingress: {
		#Embed
		...
	}
}
-- chaineddef.cue --
// evalv3 "field not allowed" regression when embedding a chain of definitions;
// chained optional-field definitions embedded in a struct should not be enforced.
// https://cuelang.org/issue/3920
// chained definitions should be handled correctly within embeddings.
issue3920: {
	out: {
		#A
		a: b: "out" // do not enforce #B
	}
	#A: a?: #B
	#B: c?: string
}
onlyCloseDirectStruct: {
	#foo: {}
	x: {y: {{a: #foo}}}
	x: y: b: 1
}
closeInEmbed: {
	x: {close({{["d"]: f: int}})}
	x: d: e: 1
}
-- embedelim.cue --
// evalv3 "field not allowed" regression with nested definitions; eliminating
// an embedded top value from a definition should not incorrectly close the struct.
// https://cuelang.org/issue/3921
issue3921: top: {
	#A: #B
	#A: b: string
	#B: _
	a: {#A & {}}
}
issue3921: hidden: {
	#A: #B
	#A: _hidden: b: string
	#B: {}
	a: {#A & {_hidden: {}}}
}
issue3921: full: {
	out: #templateList & #defineMap
	#templateList: {
		#stepMap: [string]: _
		stepList: [for c in #stepMap {c}]
	}
	#defineMap: {
		#stepMap: foo: #Step & {
			image: "bar"
			#config: {}
		}
		stepList: _
	}
	#Step: #StepInner & {
		image: string
		#config: version: string
	}
	#StepInner: image: string
}
-- issue3843.cue --
// evalv3 "field not allowed" regression when a definition is reused at
// multiple levels and pattern constraints are unified more than once.
// https://cuelang.org/issue/3843
// Pattern is unified twice. Ensure that deduping is handled correctly.
dedupPattern: t1: p1: {
	A: {
		#Z: [string]: _
		x: #Z
		x: y: z: 1
	}
	B:   A & __no_sharing
	out: A.#Z & B.x
}
dedupPattern: t1: p2: {
	A: {
		#Z: [string]: _
		x: #Z
		x: y: z: 1
	}
	B:   A & __no_sharing
	out: B.x & A.#Z
}
-- issue3858.cue --
// evalv3 "field not allowed" regression with embeddings where a definition
// with an embedded field reference was incorrectly rejected.
// https://cuelang.org/issue/3858
orig: t1: {
	#Image: embed: image: "foo:v1"
	#JobConfig: {
		image: #Image
		job: #Job & {
			image.embed
		}
	}
	#Job: {
		image: string
		vcs:   "git"
		args: [...string]
		env: [string]: string
	}

	#Output: {
		_in: _
		out: (_in & {})
	}
	#Output & {
		_in: (#JobConfig & {}).job
	}
}
reduced: t1: {
	Y: {
		a: e: "foo"
		b: X & {a}
	}
	X: {
		e: string
		f: 1 // fails in `out`
	}
	#Z: {
		_in: _
		out: _in & __no_sharing
	}
	#Z & {
		_in: Y
	}
}
orig: t2: {
	#JobConfig: {
		image: spec: image: "someimage"
		job: #Job & {
			image.spec
		}
	}
	#Job: {
		image: string
		env:   "FOO"
	}
	#Output: {
		in: _
		out: (in & {}).input
	}
	out: #Output & {
		in: input: (#JobConfig & {}).job
	}
}
reduced: t2: {
	Y: {
		a: e: "foo"
		b: X & {a}
	}
	X: {
		e: string
		f: 1 // fails
	}
	#Z: {
		_in: _
		out: _in
	}
	#Z & {_in: Y}
}
-- issue3934.cue --
// evalv3 "field not allowed" regression with disjunctions and a comprehension;
// a false-branch comprehension inside a disjunct should not trigger closedness errors.
// https://cuelang.org/issue/3934
issue3934: {
	out: #Foo & {
		foo: {
			if false {
				extra: nested: 123
			}
		}
	}
	#Foo: foo?: null | #Bar | *{bar: 3}
	#Bar: {
		bar?: int
		extra?: null | {...}
	}
}
-- large.cue --
full: {
	#Resource: {
		someMsg: string
		obs: {} | *{missing: true}

		let pickMsg = [
			if obs.missing {msg: "\(someMsg)"},
			{msg: "bar"},
		][0]
		patches: [{
			op:    "add"
			path:  "/metadata"
			value: pickMsg.msg
		}]
	}

	#Patches: [string]: _
	#JSONPatch: {
		namespace?: string
		patch: [...#JSONOp]
		output: #Patches & {(namespace): patch}
	}
	#JSONOp: {
		op:    "add"
		path:  string
		value: _
	} | {
		op:   "remove"
		path: string
	}

	#Main: {
		NS=namespace: string

		output: jsonPatch.output

		let jsonPatch = #JSONPatch & {
			let base = #Resource & {}
			let withMsg = base & {someMsg: "foo"}

			namespace: NS

			patch: withMsg.patches
		}
	}
	out: (#Main & {namespace: "ns1"}).output
}
-- ellipsis.cue --
nestedEllipsis: minimal: {
	out: #Schema & {extra: "foo"}
	#Schema: {
		#meta
		...
	}
	#meta: {}
}
nestedEllipsis: nestedWithPatterns: {
	out: #Schema & {
		objs: obj1: extra: "foo"
	}
	#Schema: {
		[_]: [_]: {
			#meta
			...
		}
		#meta: name?: int
		objs?: _
	}
}
// evalv3 "field not allowed" regression with ellipses since v0.13.0; embedding
// a schema with `...` alongside additional fields should not close the struct.
// https://cuelang.org/issue/4015
issue4015: reduced: {
	#X: {...}
	out: {
		// Embedded schema allows `a: _`. Adding `a` below should not change that.
		#X
		a: b: string
	}
	out: {
		a: {
			c: "h"
			b: "x"
		}
	}
}
issue4015: nested: {
	#X: {foo: {...}}
	out: {
		#X
		foo: {a: b: string}
	}
	out: {
		foo: a: {
			c: "h"
			b: "x"
		}
	}
}
issue4015: full: {
	#Schema: {
		cfg: {
			foo: {
				enabled:  bool | *false
				fooField: string
			}
			bar: barField: string
		}
		capacity: int | *3
	}

	#MoreCapacity: {
		capacity: 30
		...
	}

	out: #Schema
	out: {
		#MoreCapacity
		cfg: foo: enabled: true
	}
	out: {
		cfg: {
			foo: fooField: "h"
			bar: barField: "x"
		}
	}
}
-- issue3964.cue --
// evalv3 closedness regression since v0.13.1; a definition that embeds another
// definition containing a disjunction should correctly allow matching fields.
// https://cuelang.org/issue/3964
issue3964: reduced: {
	#Output: {#Embedded}
	#Embedded: {
		name: string
		#Unused | #Used
	}
	#Unused: {}
	#Used: {}
}
issue3964: full: {
	out: #Output & {
		name: "oauth2"
		used: "bar"
	}
	#Output: {#Embedded}
	#Embedded: {
		name: string
		#Unused | #Used
	}
	#Unused: unused: string
	#Used: used:     string
}
-- cycle.cue --
// evalv3 stack overflow due to latest closedness changes; mutually recursive
// definitions that embed each other caused infinite recursion during evaluation.
// https://cuelang.org/issue/4006
issue4006: {
	#A: {
		#B
		fieldA: string
	}
	#B: {#A}
	#C: #A & {}
	out: #C & #B
}
-- out/compile --
--- chaineddef.cue
{
  issue3920: {
    out: {
      〈1;#A〉
      a: {
        b: "out"
      }
    }
    #A: {
      a?: 〈1;#B〉
    }
    #B: {
      c?: string
    }
  }
  onlyCloseDirectStruct: {
    #foo: {}
    x: {
      y: {
        {
          a: 〈3;#foo〉
        }
      }
    }
    x: {
      y: {
        b: 1
      }
    }
  }
  closeInEmbed: {
    x: {
      close({
        {
          ["d"]: {
            f: int
          }
        }
      })
    }
    x: {
      d: {
        e: 1
      }
    }
  }
}
--- cycle.cue
{
  issue4006: {
    #A: {
      〈1;#B〉
      fieldA: string
    }
    #B: {
      〈1;#A〉
    }
    #C: (〈0;#A〉 & {})
    out: (〈0;#C〉 & 〈0;#B〉)
  }
}
--- disjunction.cue
{
  issue3947: {
    full: {
      #Schema: {
        allowed?: string
      }
      _defaults: {
        disallowed: (_|*"default value")
      }
      out: (〈0;#Schema〉 & 〈0;_defaults〉)
    }
  }
  issue3957: {
    reduced: {
      c: {
        a: "bar"
      }
      c: (〈0;#B〉 & {
        a: (string|*"foo")
      })
      #B: {
        b?: string
      }
    }
  }
  issue3957: {
    full: {
      #oneof: ({
        a: string
      }|{
        b?: [
          ...string,
        ]
      })
      c: (〈0;#oneof〉 & {
        a: (string|*"foo")
      })
      c: {
        a: "bar"
      }
    }
  }
  issue3957: {
    derived: {
      t1: {
        #Schema: {
          in: (string|[
            ...string,
          ])
          out: 〈import;list〉.FlattenN([
            〈1;in〉,
          ], 1)
        }
        x: (〈0;#Schema〉 & {
          in: "foo"
        })
      }
    }
  }
  issue3957: {
    derived: {
      t2: {
        #Schema: {
          in: (string|[
            ...string,
          ])
          let _flat#1 = 〈import;list〉.FlattenN([
            〈1;in〉,
          ], 1)
          out: 〈0;let _flat#1〉
        }
        out: (〈0;#Schema〉 & {
          in: "foo"
        })
      }
    }
  }
}
--- ellipsis.cue
{
  nestedEllipsis: {
    minimal: {
      out: (〈0;#Schema〉 & {
        extra: "foo"
      })
      #Schema: {
        〈1;#meta〉
        ...
      }
      #meta: {}
    }
  }
  nestedEllipsis: {
    nestedWithPatterns: {
      out: (〈0;#Schema〉 & {
        objs: {
          obj1: {
            extra: "foo"
          }
        }
      })
      #Schema: {
        [_]: {
          [_]: {
            〈2;#meta〉
            ...
          }
        }
        #meta: {
          name?: int
        }
        objs?: _
      }
    }
  }
  issue4015: {
    reduced: {
      #X: {
        ...
      }
      out: {
        〈1;#X〉
        a: {
          b: string
        }
      }
      out: {
        a: {
          c: "h"
          b: "x"
        }
      }
    }
  }
  issue4015: {
    nested: {
      #X: {
        foo: {
          ...
        }
      }
      out: {
        〈1;#X〉
        foo: {
          a: {
            b: string
          }
        }
      }
      out: {
        foo: {
          a: {
            c: "h"
            b: "x"
          }
        }
      }
    }
  }
  issue4015: {
    full: {
      #Schema: {
        cfg: {
          foo: {
            enabled: (bool|*false)
            fooField: string
          }
          bar: {
            barField: string
          }
        }
        capacity: (int|*3)
      }
      #MoreCapacity: {
        capacity: 30
        ...
      }
      out: 〈0;#Schema〉
      out: {
        〈1;#MoreCapacity〉
        cfg: {
          foo: {
            enabled: true
          }
        }
      }
      out: {
        cfg: {
          foo: {
            fooField: "h"
          }
          bar: {
            barField: "x"
          }
        }
      }
    }
  }
}
--- embedelim.cue
{
  issue3921: {
    top: {
      #A: 〈0;#B〉
      #A: {
        b: string
      }
      #B: _
      a: {
        (〈1;#A〉 & {})
      }
    }
  }
  issue3921: {
    hidden: {
      #A: 〈0;#B〉
      #A: {
        _hidden: {
          b: string
        }
      }
      #B: {}
      a: {
        (〈1;#A〉 & {
          _hidden: {}
        })
      }
    }
  }
  issue3921: {
    full: {
      out: (〈0;#templateList〉 & 〈0;#defineMap〉)
      #templateList: {
        #stepMap: {
          [string]: _
        }
        stepList: [
          for _, c in 〈1;#stepMap〉 {
            〈1;c〉
          },
        ]
      }
      #defineMap: {
        #stepMap: {
          foo: (〈2;#Step〉 & {
            image: "bar"
            #config: {}
          })
        }
        stepList: _
      }
      #Step: (〈0;#StepInner〉 & {
        image: string
        #config: {
          version: string
        }
      })
      #StepInner: {
        image: string
      }
    }
  }
}
--- in.cue
{
  embed: {
    simple: {
      #A: {
        b: 1
      }
      a: {
        〈1;#A〉
      }
      a: {
        err: 1
      }
    }
  }
  embed: {
    andInStruct: {
      #Foo: {
        a: int
      }
      a: {
        (〈1;#Foo〉 & {
          err: 2
        })
      }
    }
  }
  embed: {
    embedDefWithEmbedding: {
      #Foo: {
        {
          a: int
        }
      }
      a: {
        (〈1;#Foo〉 & {
          err: 2
        })
      }
    }
  }
  embed: {
    embedComprehension: {
      #Foo: {
        if true {
          a: int
        }
      }
      a: {
        (〈1;#Foo〉 & {
          err: 2
        })
      }
    }
  }
  embed: {
    fieldWithAnd: {
      #A: {}
      {
        a: (〈1;#A〉 & {
          err: 3
        })
      }
    }
  }
  embed: {
    embedAndRecursive: {
      #A: {
        a: int
      }
      B: {
        x: 〈1;#A〉
      }
      (〈0;B〉 & {
        x: {
          err: 2
        }
      })
    }
  }
  embed: {
    andEmbed: {
      #A: {
        b: int
      }
      #B: {
        b: int
      }
      #D: {
        (〈1;#A〉 & 〈1;#B〉)
      }
      d: (〈0;#D〉 & {
        err: 3
      })
    }
  }
  and: {
    transitive: {
      ok: {
        Z: {
          a: string
        }
        #Y: 〈0;Z〉
        #X: (〈0;#Y〉 & 〈0;Z〉)
        out: (〈0;#X〉 & {
          a: "foo"
        })
      }
    }
  }
  and: {
    transitive: {
      err: {
        Z: {
          a: string
        }
        #Y: 〈0;Z〉
        #X: (〈0;#Y〉 & 〈0;Z〉)
        out: (〈0;#X〉 & {
          err: "foo"
        })
      }
    }
  }
  and: {
    transitiveWithEmbed: {
      ok: {
        Z: {
          a: string
        }
        #X: (〈0;#Y〉 & 〈0;Z〉)
        #Y: {
          〈1;Z〉
        }
        out: (〈0;#X〉 & {
          a: "foo"
        })
      }
    }
  }
  and: {
    transitiveWithEmbed: {
      err: {
        Z: {
          a: string
        }
        #X: (〈0;#Y〉 & 〈0;Z〉)
        #Y: {
          〈1;Z〉
        }
        out: (〈0;#X〉 & {
          err: "foo"
        })
      }
    }
  }
  embed: {
    nonDef: {
      t1: {
        X: {
          a: string
        }
        #Y: (〈0;#Z〉 & 〈0;X〉)
        #Z: {
          〈1;X〉
          b?: string
        }
      }
    }
  }
  embed: {
    defAndHidden: {
      full: {
        _stepCommon: {
          Name: string
        }
        #Step: (〈0;#Command〉 & 〈0;_stepCommon〉)
        #Command: {
          〈1;_stepCommon〉
          Path?: string
        }
        out: (〈0;#Step〉 & {
          Name: "foo"
        })
      }
    }
  }
  embed: {
    withIndirect: {
      A: 〈0;#B〉
      #B: {
        b: int
      }
      (〈0;A〉 & {
        err: 2
      })
    }
  }
}
--- inline.cue
{
  embedInline: {
    #Schema: {
      a: "hello"
      b: {
        {
          x: {
            c: "foo"
          }
        }.x
      }
      b: {
        c: string
        d: "never printed"
      }
    }
    out: (〈0;#Schema〉 & _|_(no sharing))
  }
  issue3853: {
    #Schema: {
      a: "hello"
      b: {
        {
          x: {
            c: "foo"
          }
        }.x
      }
      b: {
        c: string
        d: "never printed"
      }
    }
    out: {
      x: (〈1;#Schema〉 & {}).a
    }.x
  }
}
--- issue3832.cue
{
  issue3832: {
    _person: {
      self: {
        firstName: "Sam"
      }
    }
    #T: {
      _subject: {
        in: _
        out: {
          let self#2 = 〈1;in〉.self
          outFirstName: 〈0;let self#2〉.firstName
        }
      }
      _assert: {
        pass: _
      }
      _assert: ({
        check!: _
        pass: "never"
      }|{
        invoke!: _
        pass: (〈1;_subject〉 & {
          in: 〈1;invoke〉
        }).out
      })
      results: 〈0;_assert〉.pass
    }
    (〈0;#T〉 & {
      _assert: {
        invoke: 〈2;_person〉
      }
    })
  }
}
--- issue3833.cue
{
  issue3833: {
    ok: {
      out: {
        (〈1;#A〉 & {
          a: 〈2;#B〉
        })
      }
      #A: {
        a: {
          b: string
          ...
        }
        ...
      }
      #C: {
        c: string
      }
      #B: {
        (〈1;#C〉 & {
          c: "foo"
        })
        b: "foo"
      }
    }
  }
  issue3833: {
    evalv2Issue: {
      out: {
        (〈1;#A〉 & {
          a: 〈2;#B〉
        })
      }
      #A: {
        a: {
          b: string
        }
        ...
      }
      #C: {
        c: string
      }
      #B: {
        (〈1;#C〉 & {
          c: "foo"
        })
        b: "foo"
      }
    }
  }
}
--- issue3837.cue
{
  issue3837: {
    reduced: {
      A: {
        〈1;#Embed〉
        extra: "foo"
      }
      out: {
        {
          x: (〈2;A〉 & _|_(no sharing))
        }
      }
      #Embed: {}
    }
  }
  issue3837: {
    full: {
      #Embed: {}
      #A: {
        〈1;#Embed〉
        extra: "foo"
      }
      #B: (〈0;#C〉|{})
      #C: {
        bar: string
      }
      out: (〈0;#B〉 & {
        bar: "baz"
        {
          #def: (〈2;#A〉 & _|_(no sharing))
        }
      })
    }
  }
}
--- issue3839.cue
{
  issue3839: {
    reduced: {
      x: {
        (〈1;A〉 & _|_(no sharing))
      }
      x: {
        y: 1
      }
      #B: {}
      A: {
        〈1;#B〉
        ...
      }
    }
  }
  issue3839: {
    full: {
      _globals: {
        glb: {
          globalField: ""
        }
      }
      #GlobalContext: {
        globalField: string
      }
      #Context: {
        glb: 〈1;#GlobalContext〉
        out: 〈0;glb〉
      }
      out: {
        ingress: {
          (〈2;#Ingress〉 & {
            #def: (〈3;#Context〉 & 〈3;_globals〉).out
          })
        }
        ingress?: {
          foo: 1234
          bar: "http"
        }
      }
      #Embed: {
        #def: {
          ...
        }
      }
      #Ingress: {
        〈1;#Embed〉
        ...
      }
    }
  }
}
--- issue3843.cue
{
  dedupPattern: {
    t1: {
      p1: {
        A: {
          #Z: {
            [string]: _
          }
          x: 〈0;#Z〉
          x: {
            y: {
              z: 1
            }
          }
        }
        B: (〈0;A〉 & _|_(no sharing))
        out: (〈0;A〉.#Z & 〈0;B〉.x)
      }
    }
  }
  dedupPattern: {
    t1: {
      p2: {
        A: {
          #Z: {
            [string]: _
          }
          x: 〈0;#Z〉
          x: {
            y: {
              z: 1
            }
          }
        }
        B: (〈0;A〉 & _|_(no sharing))
        out: (〈0;B〉.x & 〈0;A〉.#Z)
      }
    }
  }
}
--- issue3858.cue
{
  orig: {
    t1: {
      #Image: {
        embed: {
          image: "foo:v1"
        }
      }
      #JobConfig: {
        image: 〈1;#Image〉
        job: (〈1;#Job〉 & {
          〈1;image〉.embed
        })
      }
      #Job: {
        image: string
        vcs: "git"
        args: [
          ...string,
        ]
        env: {
          [string]: string
        }
      }
      #Output: {
        _in: _
        out: (〈0;_in〉 & {})
      }
      (〈0;#Output〉 & {
        _in: (〈1;#JobConfig〉 & {}).job
      })
    }
  }
  reduced: {
    t1: {
      Y: {
        a: {
          e: "foo"
        }
        b: (〈1;X〉 & {
          〈1;a〉
        })
      }
      X: {
        e: string
        f: 1
      }
      #Z: {
        _in: _
        out: (〈0;_in〉 & _|_(no sharing))
      }
      (〈0;#Z〉 & {
        _in: 〈1;Y〉
      })
    }
  }
  orig: {
    t2: {
      #JobConfig: {
        image: {
          spec: {
            image: "someimage"
          }
        }
        job: (〈1;#Job〉 & {
          〈1;image〉.spec
        })
      }
      #Job: {
        image: string
        env: "FOO"
      }
      #Output: {
        in: _
        out: (〈0;in〉 & {}).input
      }
      out: (〈0;#Output〉 & {
        in: {
          input: (〈2;#JobConfig〉 & {}).job
        }
      })
    }
  }
  reduced: {
    t2: {
      Y: {
        a: {
          e: "foo"
        }
        b: (〈1;X〉 & {
          〈1;a〉
        })
      }
      X: {
        e: string
        f: 1
      }
      #Z: {
        _in: _
        out: 〈0;_in〉
      }
      (〈0;#Z〉 & {
        _in: 〈1;Y〉
      })
    }
  }
}
--- issue3934.cue
{
  issue3934: {
    out: (〈0;#Foo〉 & {
      foo: {
        if false {
          extra: {
            nested: 123
          }
        }
      }
    })
    #Foo: {
      foo?: (null|〈1;#Bar〉|*{
        bar: 3
      })
    }
    #Bar: {
      bar?: int
      extra?: (null|{
        ...
      })
    }
  }
}
--- issue3964.cue
{
  issue3964: {
    reduced: {
      #Output: {
        〈1;#Embedded〉
      }
      #Embedded: {
        name: string
        (〈1;#Unused〉|〈1;#Used〉)
      }
      #Unused: {}
      #Used: {}
    }
  }
  issue3964: {
    full: {
      out: (〈0;#Output〉 & {
        name: "oauth2"
        used: "bar"
      })
      #Output: {
        〈1;#Embedded〉
      }
      #Embedded: {
        name: string
        (〈1;#Unused〉|〈1;#Used〉)
      }
      #Unused: {
        unused: string
      }
      #Used: {
        used: string
      }
    }
  }
}
--- large.cue
{
  full: {
    #Resource: {
      someMsg: string
      obs: ({}|*{
        missing: true
      })
      let pickMsg#3 = [
        if 〈1;obs〉.missing {
          msg: "\(〈2;someMsg〉)"
        },
        {
          msg: "bar"
        },
      ][0]
      patches: [
        {
          op: "add"
          path: "/metadata"
          value: 〈2;let pickMsg#3〉.msg
        },
      ]
    }
    #Patches: {
      [string]: _
    }
    #JSONPatch: {
      namespace?: string
      patch: [
        ...〈2;#JSONOp〉,
      ]
      output: (〈1;#Patches〉 & {
        〈1;namespace〉: 〈1;patch〉
      })
    }
    #JSONOp: ({
      op: "add"
      path: string
      value: _
    }|{
      op: "remove"
      path: string
    })
    #Main: {
      namespace: string
      output: 〈0;let jsonPatch#4〉.output
      let jsonPatch#4 = (〈1;#JSONPatch〉 & {
        let base#7 = (〈2;#Resource〉 & {})
        let withMsg#8 = (〈0;let base#7〉 & {
          someMsg: "foo"
        })
        namespace: 〈1;namespace〉
        patch: 〈0;let withMsg#8〉.patches
      })
    }
    out: (〈0;#Main〉 & {
      namespace: "ns1"
    }).output
  }
}
--- validators.cue
{
  embed: {
    normalValidator: {
      #X: {
        〈import;struct〉.MaxFields(1)
        a?: int
        b?: int
      }
      x: 〈0;#X〉
      x: {
        err: 1
      }
    }
  }
  embed: {
    openValidator: {
      t1: {
        #X: {
          matchN(0, [])
          a?: int
          b?: int
        }
        x: 〈0;#X〉
        x: {
          err: 1
        }
      }
    }
  }
  embed: {
    openValidator: {
      t2: {
        Y: matchN(1, [
          〈1;X〉,
        ])
        X: {
          b?: 〈1;Y〉
        }
        a: 〈0;X〉
        a: {
          b: 1
        }
      }
    }
  }
  disjunction: {
    withErr: {
      t1: {
        params: {}
        out: (〈0;#Schema1〉 & {
          b1: {
            b2: {
              b3: 〈3;params〉.mayExistLater
            }
          }
        })
        #Schema1: {
          b1?: (null|〈1;#Schema2〉)
        }
        #Schema2: {
          b2?: (null|{
            b3?: string
          })
        }
      }
    }
  }
  embed: {
    nestedValidator: {
      #types: {
        z?: 〈import;list〉.UniqueItems
      }
      x: {
        y: {
          z: [
            1,
          ]
        }
      }
      x: {
        〈1;#def〉
        y?: 〈1;#types〉
      }
      #def: {}
    }
  }
}
