@@ -2210,31 +2210,19 @@ namespace {
22102210 oneWayVarType = CS.createTypeVariable (
22112211 CS.getConstraintLocator (locator), TVO_CanBindToNoEscape);
22122212
2213- // If there is an externally-imposed pattern type and the
2214- // binding/capture is marked as `weak`, let's make sure
2215- // that the imposed type is optional .
2213+ // If there is externally-imposed type, and the variable
2214+ // is marked as `weak`, let's fallthrough and allow the
2215+ // `one-way` constraint to be fixed in diagnostic mode .
22162216 //
2217- // Note that there is no need to check `varType` since
2218- // it's only "externally" bound if this pattern isn't marked
2219- // as `weak`.
2220- if (externalPatternType &&
2221- optionality == ReferenceOwnershipOptionality::Required) {
2222- // If the type is not yet known, let's add a constraint
2223- // to make sure that it can only be bound to an optional type.
2224- if (externalPatternType->isTypeVariableOrMember ()) {
2225- auto objectTy = CS.createTypeVariable (
2226- CS.getConstraintLocator (locator.withPathElement (
2227- ConstraintLocator::OptionalPayload)),
2228- TVO_CanBindToLValue | TVO_CanBindToNoEscape);
2229-
2230- CS.addConstraint (ConstraintKind::OptionalObject,
2231- externalPatternType, objectTy, locator);
2232- } else if (!externalPatternType->getOptionalObjectType ()) {
2233- // TODO(diagnostics): A tailored fix to indiciate that `weak`
2234- // should have an optional type.
2235- return Type ();
2236- }
2237- }
2217+ // That would make sure that type of this variable is
2218+ // recorded in the constraint system, which would then
2219+ // be used instead of `getVarType` upon discovering a
2220+ // reference to this variable in subsequent expression(s).
2221+ //
2222+ // If we let constraint generation fail here, it would trigger
2223+ // interface type request via `var->getType()` that would
2224+ // attempt to validate `weak` attribute, and produce a
2225+ // diagnostic in the middle of the solver path.
22382226
22392227 CS.addConstraint (ConstraintKind::OneWayEqual, oneWayVarType,
22402228 externalPatternType ? externalPatternType : varType,
0 commit comments