-- in.cue --
self: t1: {
	a?: int
}

self: t2: {
	a!: int
	a!: int
}

unify: t1: {
	a!: int
	a:  int
}

unify: t2: {
	a!: int
	a?: int
}

#Def: t1: {
	a!: int
}

// Required fields do not cause vet to fail with definitions: a required field
// in one definition should block a disallowed field from another definition.
// https://cuelang.org/issue/2306
allowed: {
	issue2306: {
		#A: a!: int
		#A: #B

		#B: b!: int
	}
}

reference: {
	toWithinDefinition: {
		#Foo: a!: int
		b: #Foo.a
	}
	toFieldFromDefinition: {
		#Foo: a!: int
		b: #Foo
		c: b.a
	}
	toNonDefinition: {
		x: y!: _
		b: x.y
	}
	toConcrete: {
		a!: 1
		b:  a + 1
	}
	// A reference to a required-but-missing field reports "required field
	// missing", not "cannot reference optional field".
	// https://cuelang.org/issue/2937
	issue2937: {
		min!: number
		max!: number & >min
		max:  10
	}
}
-- issue3918.cue --
import "strings"

// Required fields do not work on the function pattern: a required field used
// as an input to a definition-based function was not satisfied at the call site.
// https://cuelang.org/issue/3918
issue3918: {
	reduced: {
		#disjuncts: {
			in!: [...string]
			out: strings.Join(in, "|")
		}

		x: (#disjuncts & {
			in: ["foo", "bar"]
		}).out
	}
	noFunction: {
		#disjuncts: {
			in!: [...string]
			out: in
		}
		_foo: #disjuncts & {}
		x: _foo.out
	}
}
// A required field error is incomplete error. Ensure that setting a vertex
// to this error does not escalate it to an evaluation error.
doNotEscalateError: {
	a: {
		in:  _
		out: in.self
	}
	b: {
		required!: _
		pass: (a & {in: required}).out
	}
}
-- out/compile --
--- in.cue
{
  self: {
    t1: {
      a?: int
    }
  }
  self: {
    t2: {
      a!: int
      a!: int
    }
  }
  unify: {
    t1: {
      a!: int
      a: int
    }
  }
  unify: {
    t2: {
      a!: int
      a?: int
    }
  }
  #Def: {
    t1: {
      a!: int
    }
  }
  allowed: {
    issue2306: {
      #A: {
        a!: int
      }
      #A: 〈0;#B〉
      #B: {
        b!: int
      }
    }
  }
  reference: {
    toWithinDefinition: {
      #Foo: {
        a!: int
      }
      b: 〈0;#Foo〉.a
    }
    toFieldFromDefinition: {
      #Foo: {
        a!: int
      }
      b: 〈0;#Foo〉
      c: 〈0;b〉.a
    }
    toNonDefinition: {
      x: {
        y!: _
      }
      b: 〈0;x〉.y
    }
    toConcrete: {
      a!: 1
      b: (〈0;a〉 + 1)
    }
    issue2937: {
      min!: number
      max!: (number & >〈0;min〉)
      max: 10
    }
  }
}
--- issue3918.cue
{
  issue3918: {
    reduced: {
      #disjuncts: {
        in!: [
          ...string,
        ]
        out: 〈import;strings〉.Join(〈0;in〉, "|")
      }
      x: (〈0;#disjuncts〉 & {
        in: [
          "foo",
          "bar",
        ]
      }).out
    }
    noFunction: {
      #disjuncts: {
        in!: [
          ...string,
        ]
        out: 〈0;in〉
      }
      _foo: (〈0;#disjuncts〉 & {})
      x: 〈0;_foo〉.out
    }
  }
  doNotEscalateError: {
    a: {
      in: _
      out: 〈0;in〉.self
    }
    b: {
      required!: _
      pass: (〈1;a〉 & {
        in: 〈1;required〉
      }).out
    }
  }
}
