@@ -560,15 +560,17 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
560
560
selfType = foundDC->getSelfInterfaceType ();
561
561
562
562
if (selfType->is <GenericTypeParamType>()) {
563
- if (isa<ProtocolDecl>(typeDecl->getDeclContext ())) {
564
- if (isa<AssociatedTypeDecl>(typeDecl) ||
565
- (isa<TypeAliasDecl>(typeDecl) &&
566
- !cast<TypeAliasDecl>(typeDecl)->isGeneric () &&
567
- !isSpecialized)) {
568
- if (getStage () == TypeResolutionStage::Structural) {
569
- return DependentMemberType::get (selfType, typeDecl->getName ());
570
- } else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
571
- typeDecl = assocType->getAssociatedTypeAnchor ();
563
+ if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
564
+ if (getStage () == TypeResolutionStage::Structural) {
565
+ return DependentMemberType::get (selfType, typeDecl->getName ());
566
+ }
567
+
568
+ typeDecl = assocType->getAssociatedTypeAnchor ();
569
+ } else if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
570
+ if (isa<ProtocolDecl>(typeDecl->getDeclContext ()) &&
571
+ getStage () == TypeResolutionStage::Structural) {
572
+ if (aliasDecl && !aliasDecl->isGeneric ()) {
573
+ return adjustAliasType (aliasDecl->getStructuralType ());
572
574
}
573
575
}
574
576
}
@@ -5950,42 +5952,39 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
5950
5952
if (constraintType->hasError ())
5951
5953
return ErrorType::get (getASTContext ());
5952
5954
5955
+ if (constraintType->isConstraintType ()) {
5956
+ return ExistentialType::get (constraintType);
5957
+ }
5958
+
5953
5959
// TO-DO: generalize this and emit the same erorr for some P?
5954
- if (!constraintType->isConstraintType ()) {
5955
- // Emit a tailored diagnostic for the incorrect optional
5956
- // syntax 'any P?' with a fix-it to add parenthesis.
5957
- auto wrapped = constraintType->getOptionalObjectType ();
5958
- if (wrapped && (wrapped->is <ExistentialType>() ||
5959
- wrapped->is <ExistentialMetatypeType>())) {
5960
- std::string fix;
5961
- llvm::raw_string_ostream OS (fix);
5962
- constraintType->print (OS, PrintOptions::forDiagnosticArguments ());
5963
- diagnose (repr->getLoc (), diag::incorrect_optional_any,
5964
- constraintType)
5960
+ //
5961
+ // Emit a tailored diagnostic for the incorrect optional
5962
+ // syntax 'any P?' with a fix-it to add parenthesis.
5963
+ auto wrapped = constraintType->getOptionalObjectType ();
5964
+ if (wrapped && (wrapped->is <ExistentialType>() ||
5965
+ wrapped->is <ExistentialMetatypeType>())) {
5966
+ std::string fix;
5967
+ llvm::raw_string_ostream OS (fix);
5968
+ constraintType->print (OS, PrintOptions::forDiagnosticArguments ());
5969
+ diagnose (repr->getLoc (), diag::incorrect_optional_any, constraintType)
5965
5970
.fixItReplace (repr->getSourceRange (), fix);
5966
5971
5967
- // Recover by returning the intended type, but mark the type
5968
- // representation as invalid to prevent it from being diagnosed elsewhere.
5969
- repr->setInvalid ();
5970
- return constraintType;
5971
- }
5972
-
5972
+ // Recover by returning the intended type, but mark the type
5973
+ // representation as invalid to prevent it from being diagnosed elsewhere.
5974
+ repr->setInvalid ();
5975
+ } else if (constraintType->is <ExistentialType>()) {
5973
5976
// Diagnose redundant `any` on an already existential type e.g. any (any P)
5974
5977
// with a fix-it to remove first any.
5975
- if (constraintType->is <ExistentialType>()) {
5976
- diagnose (repr->getLoc (), diag::redundant_any_in_existential,
5977
- ExistentialType::get (constraintType))
5978
- .fixItRemove (repr->getAnyLoc ());
5979
- return constraintType;
5980
- }
5981
-
5978
+ diagnose (repr->getLoc (), diag::redundant_any_in_existential,
5979
+ ExistentialType::get (constraintType))
5980
+ .fixItRemove (repr->getAnyLoc ());
5981
+ } else {
5982
5982
diagnose (repr->getLoc (), diag::any_not_existential,
5983
5983
constraintType->isTypeParameter (), constraintType)
5984
5984
.fixItRemove (repr->getAnyLoc ());
5985
- return constraintType;
5986
5985
}
5987
5986
5988
- return ExistentialType::get ( constraintType) ;
5987
+ return constraintType;
5989
5988
}
5990
5989
5991
5990
NeverNullType TypeResolver::resolveMetatypeType (MetatypeTypeRepr *repr,
0 commit comments