@@ -13598,21 +13598,41 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1359813598 }
1359913599
1360013600 decl = overloadChoice.getDecl();
13601+
1360113602 auto openedOverloadTypes = getOpenedTypes(overloadLocator);
1360213603 openedTypes.append(openedOverloadTypes.begin(), openedOverloadTypes.end());
1360313604 }
1360413605
13605- auto genericContext = decl->getAsGenericContext();
13606- if (!genericContext)
13606+ std::function<GenericParamList *(ValueDecl *)> getGenericParams =
13607+ [&](ValueDecl *decl) -> GenericParamList * {
13608+ auto genericContext = decl->getAsGenericContext();
13609+ if (!genericContext)
13610+ return nullptr;
13611+
13612+ auto genericParams = genericContext->getGenericParams();
13613+ if (!genericParams) {
13614+ // If declaration is a non-generic typealias, let's point
13615+ // to the underlying generic declaration.
13616+ if (auto *TA = dyn_cast<TypeAliasDecl>(decl)) {
13617+ if (auto *UGT = TA->getUnderlyingType()->getAs<AnyGenericType>())
13618+ return getGenericParams(UGT->getDecl());
13619+ }
13620+ }
13621+
13622+ return genericParams;
13623+ };
13624+
13625+ if (!decl->getAsGenericContext())
1360713626 return SolutionKind::Error;
1360813627
13609- auto genericParams = genericContext-> getGenericParams();
13610- if (!genericParams || genericParams->size() == 0 ) {
13628+ auto genericParams = getGenericParams(decl );
13629+ if (!genericParams) {
1361113630 // FIXME: Record an error here that we're ignoring the parameters.
1361213631 return SolutionKind::Solved;
1361313632 }
1361413633
1361513634 // Map the generic parameters we have over to their opened types.
13635+ bool hasParameterPack = false;
1361613636 SmallVector<Type, 2> openedGenericParams;
1361713637 auto genericParamDepth = genericParams->getParams()[0]->getDepth();
1361813638 for (const auto &openedType : openedTypes) {
@@ -13634,19 +13654,38 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1363413654
1363513655 auto *expansion = PackExpansionType::get(patternType, shapeType);
1363613656 openedGenericParams.push_back(expansion);
13657+ hasParameterPack = true;
1363713658 } else {
1363813659 openedGenericParams.push_back(Type(openedType.second));
1363913660 }
1364013661 }
1364113662 }
13663+
13664+ if (openedGenericParams.empty()) {
13665+ if (!shouldAttemptFixes())
13666+ return SolutionKind::Error;
13667+
13668+ return recordFix(AllowConcreteTypeSpecialization::create(
13669+ *this, type1, getConstraintLocator(locator)))
13670+ ? SolutionKind::Error
13671+ : SolutionKind::Solved;
13672+ }
13673+
1364213674 assert(openedGenericParams.size() == genericParams->size());
1364313675
1364413676 // Match the opened generic parameters to the specialized arguments.
1364513677 auto specializedArgs = type2->castTo<PackType>()->getElementTypes();
1364613678 PackMatcher matcher(openedGenericParams, specializedArgs, getASTContext(),
1364713679 isPackExpansionType);
13648- if (matcher.match())
13649- return SolutionKind::Error;
13680+ if (matcher.match()) {
13681+ if (!shouldAttemptFixes())
13682+ return SolutionKind::Error;
13683+
13684+ auto *fix = IgnoreGenericSpecializationArityMismatch::create(
13685+ *this, decl, openedGenericParams.size(), specializedArgs.size(),
13686+ hasParameterPack, getConstraintLocator(locator));
13687+ return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
13688+ }
1365013689
1365113690 // Bind the opened generic parameters to the specialization arguments.
1365213691 for (const auto &pair : matcher.pairs) {
@@ -14746,7 +14785,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1474614785 case FixKind::MacroMissingPound:
1474714786 case FixKind::AllowGlobalActorMismatch:
1474814787 case FixKind::AllowAssociatedValueMismatch:
14749- case FixKind::GenericArgumentsMismatch: {
14788+ case FixKind::GenericArgumentsMismatch:
14789+ case FixKind::AllowConcreteTypeSpecialization:
14790+ case FixKind::IgnoreGenericSpecializationArityMismatch: {
1475014791 return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1475114792 }
1475214793 case FixKind::IgnoreInvalidASTNode: {
0 commit comments