@@ -4745,14 +4745,30 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
47454745 continue ;
47464746
47474747 // As a narrow fix for a source compatibility issue with SwiftUI's
4748- // swiftinterface, allow the conformance if the underlying type of
4749- // the typealias is Never.
4748+ // swiftinterface, allow a 'typealias' type witness with an underlying type
4749+ // of 'Never' if it is declared in a context that does not satisfy the
4750+ // requirements of the conformance context.
47504751 //
4751- // FIXME: This should be conditionalized on a new language version.
4752+ // FIXME: If SwiftUI redeclares the typealias under the correct constraints,
4753+ // this can be removed.
47524754 bool skipRequirementCheck = false ;
47534755 if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
4754- if (typeAliasDecl->getUnderlyingType ()->isUninhabited ())
4755- skipRequirementCheck = true ;
4756+ if (typeAliasDecl->getUnderlyingType ()->isNever ()) {
4757+ if (typeAliasDecl->getParentModule ()->getName ().is (" SwiftUI" )) {
4758+ if (typeAliasDecl->getDeclContext ()->getSelfNominalTypeDecl () ==
4759+ Adoptee->getAnyNominal ()) {
4760+ const auto reqs =
4761+ typeAliasDecl->getGenericSignature ().requirementsNotSatisfiedBy (
4762+ DC->getGenericSignatureOfContext ());
4763+ if (!reqs.empty ()) {
4764+ SwiftUIInvalidTyWitness = {assocType, typeAliasDecl,
4765+ reqs.front ()};
4766+
4767+ skipRequirementCheck = true ;
4768+ }
4769+ }
4770+ }
4771+ }
47564772 }
47574773
47584774 // Skip typealiases with an unbound generic type as their underlying type.
@@ -5216,6 +5232,36 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
52165232 }
52175233 }
52185234 }
5235+
5236+ if (Conformance->isInvalid ()) {
5237+ return ;
5238+ }
5239+
5240+ // As a narrow fix for a source compatibility issue with SwiftUI's
5241+ // swiftinterface, but only if the conformance succeeds, warn about an
5242+ // actually malformed conformance if we recorded a 'typealias' type witness
5243+ // with an underlying type of 'Never', which resides in a context that does
5244+ // not satisfy the requirements of the conformance context.
5245+ //
5246+ // FIXME: If SwiftUI redeclares the typealias under the correct constraints,
5247+ // this can be removed.
5248+ if (SwiftUIInvalidTyWitness) {
5249+ const auto &info = SwiftUIInvalidTyWitness.getValue ();
5250+ const auto &failedReq = info.FailedReq ;
5251+
5252+ auto &diags = getASTContext ().Diags ;
5253+ diags.diagnose (Loc, diag::type_does_not_conform_swiftui_warning, Adoptee,
5254+ Proto->getDeclaredInterfaceType ());
5255+ diags.diagnose (info.AssocTypeDecl , diag::no_witnesses_type,
5256+ info.AssocTypeDecl ->getName ());
5257+
5258+ if (failedReq.getKind () != RequirementKind::Layout) {
5259+ diags.diagnose (info.TypeWitnessDecl ,
5260+ diag::protocol_type_witness_missing_requirement,
5261+ failedReq.getFirstType (), failedReq.getSecondType (),
5262+ (unsigned )failedReq.getKind ());
5263+ }
5264+ }
52195265}
52205266
52215267// / Retrieve the Objective-C method key from the given function.
0 commit comments