@@ -13584,21 +13584,41 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1358413584 }
1358513585
1358613586 decl = overloadChoice.getDecl();
13587+
1358713588 auto openedOverloadTypes = getOpenedTypes(overloadLocator);
1358813589 openedTypes.append(openedOverloadTypes.begin(), openedOverloadTypes.end());
1358913590 }
1359013591
13591- auto genericContext = decl->getAsGenericContext();
13592- if (!genericContext)
13592+ std::function<GenericParamList *(ValueDecl *)> getGenericParams =
13593+ [&](ValueDecl *decl) -> GenericParamList * {
13594+ auto genericContext = decl->getAsGenericContext();
13595+ if (!genericContext)
13596+ return nullptr;
13597+
13598+ auto genericParams = genericContext->getGenericParams();
13599+ if (!genericParams) {
13600+ // If declaration is a non-generic typealias, let's point
13601+ // to the underlying generic declaration.
13602+ if (auto *TA = dyn_cast<TypeAliasDecl>(decl)) {
13603+ if (auto *UGT = TA->getUnderlyingType()->getAs<AnyGenericType>())
13604+ return getGenericParams(UGT->getDecl());
13605+ }
13606+ }
13607+
13608+ return genericParams;
13609+ };
13610+
13611+ if (!decl->getAsGenericContext())
1359313612 return SolutionKind::Error;
1359413613
13595- auto genericParams = genericContext-> getGenericParams();
13596- if (!genericParams || genericParams->size() == 0 ) {
13614+ auto genericParams = getGenericParams(decl );
13615+ if (!genericParams) {
1359713616 // FIXME: Record an error here that we're ignoring the parameters.
1359813617 return SolutionKind::Solved;
1359913618 }
1360013619
1360113620 // Map the generic parameters we have over to their opened types.
13621+ bool hasParameterPack = false;
1360213622 SmallVector<Type, 2> openedGenericParams;
1360313623 auto genericParamDepth = genericParams->getParams()[0]->getDepth();
1360413624 for (const auto &openedType : openedTypes) {
@@ -13620,19 +13640,38 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1362013640
1362113641 auto *expansion = PackExpansionType::get(patternType, shapeType);
1362213642 openedGenericParams.push_back(expansion);
13643+ hasParameterPack = true;
1362313644 } else {
1362413645 openedGenericParams.push_back(Type(openedType.second));
1362513646 }
1362613647 }
1362713648 }
13649+
13650+ if (openedGenericParams.empty()) {
13651+ if (!shouldAttemptFixes())
13652+ return SolutionKind::Error;
13653+
13654+ return recordFix(AllowConcreteTypeSpecialization::create(
13655+ *this, type1, getConstraintLocator(locator)))
13656+ ? SolutionKind::Error
13657+ : SolutionKind::Solved;
13658+ }
13659+
1362813660 assert(openedGenericParams.size() == genericParams->size());
1362913661
1363013662 // Match the opened generic parameters to the specialized arguments.
1363113663 auto specializedArgs = type2->castTo<PackType>()->getElementTypes();
1363213664 PackMatcher matcher(openedGenericParams, specializedArgs, getASTContext(),
1363313665 isPackExpansionType);
13634- if (matcher.match())
13635- return SolutionKind::Error;
13666+ if (matcher.match()) {
13667+ if (!shouldAttemptFixes())
13668+ return SolutionKind::Error;
13669+
13670+ auto *fix = IgnoreGenericSpecializationArityMismatch::create(
13671+ *this, decl, openedGenericParams.size(), specializedArgs.size(),
13672+ hasParameterPack, getConstraintLocator(locator));
13673+ return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
13674+ }
1363613675
1363713676 // Bind the opened generic parameters to the specialization arguments.
1363813677 for (const auto &pair : matcher.pairs) {
@@ -14732,7 +14771,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1473214771 case FixKind::MacroMissingPound:
1473314772 case FixKind::AllowGlobalActorMismatch:
1473414773 case FixKind::AllowAssociatedValueMismatch:
14735- case FixKind::GenericArgumentsMismatch: {
14774+ case FixKind::GenericArgumentsMismatch:
14775+ case FixKind::AllowConcreteTypeSpecialization:
14776+ case FixKind::IgnoreGenericSpecializationArityMismatch: {
1473614777 return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1473714778 }
1473814779 case FixKind::IgnoreInvalidASTNode: {
0 commit comments