@@ -4691,14 +4691,30 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
46914691 continue ;
46924692
46934693 // As a narrow fix for a source compatibility issue with SwiftUI's
4694- // swiftinterface, allow the conformance if the underlying type of
4695- // the typealias is Never.
4694+ // swiftinterface, allow a 'typealias' type witness with an underlying type
4695+ // of 'Never' if it is declared in a context that does not satisfy the
4696+ // requirements of the conformance context.
46964697 //
4697- // FIXME: This should be conditionalized on a new language version.
4698+ // FIXME: If SwiftUI redeclares the typealias under the correct constraints,
4699+ // this can be removed.
46984700 bool skipRequirementCheck = false ;
46994701 if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
4700- if (typeAliasDecl->getUnderlyingType ()->isUninhabited ())
4701- skipRequirementCheck = true ;
4702+ if (typeAliasDecl->getUnderlyingType ()->isNever ()) {
4703+ if (typeAliasDecl->getParentModule ()->getName ().is (" SwiftUI" )) {
4704+ if (typeAliasDecl->getDeclContext ()->getSelfNominalTypeDecl () ==
4705+ Adoptee->getAnyNominal ()) {
4706+ const auto reqs =
4707+ typeAliasDecl->getGenericSignature ().requirementsNotSatisfiedBy (
4708+ DC->getGenericSignatureOfContext ());
4709+ if (!reqs.empty ()) {
4710+ SwiftUIInvalidTyWitness = {assocType, typeAliasDecl,
4711+ reqs.front ()};
4712+
4713+ skipRequirementCheck = true ;
4714+ }
4715+ }
4716+ }
4717+ }
47024718 }
47034719
47044720 // Skip typealiases with an unbound generic type as their underlying type.
@@ -5162,6 +5178,36 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
51625178 }
51635179 }
51645180 }
5181+
5182+ if (Conformance->isInvalid ()) {
5183+ return ;
5184+ }
5185+
5186+ // As a narrow fix for a source compatibility issue with SwiftUI's
5187+ // swiftinterface, but only if the conformance succeeds, warn about an
5188+ // actually malformed conformance if we recorded a 'typealias' type witness
5189+ // with an underlying type of 'Never', which resides in a context that does
5190+ // not satisfy the requirements of the conformance context.
5191+ //
5192+ // FIXME: If SwiftUI redeclares the typealias under the correct constraints,
5193+ // this can be removed.
5194+ if (SwiftUIInvalidTyWitness) {
5195+ const auto &info = SwiftUIInvalidTyWitness.getValue ();
5196+ const auto &failedReq = info.FailedReq ;
5197+
5198+ auto &diags = getASTContext ().Diags ;
5199+ diags.diagnose (Loc, diag::type_does_not_conform_swiftui_warning, Adoptee,
5200+ Proto->getDeclaredInterfaceType ());
5201+ diags.diagnose (info.AssocTypeDecl , diag::no_witnesses_type,
5202+ info.AssocTypeDecl ->getName ());
5203+
5204+ if (failedReq.getKind () != RequirementKind::Layout) {
5205+ diags.diagnose (info.TypeWitnessDecl ,
5206+ diag::protocol_type_witness_missing_requirement,
5207+ failedReq.getFirstType (), failedReq.getSecondType (),
5208+ (unsigned )failedReq.getKind ());
5209+ }
5210+ }
51655211}
51665212
51675213// / Retrieve the Objective-C method key from the given function.
0 commit comments