@@ -5904,42 +5904,39 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
59045904 if (constraintType->hasError ())
59055905 return ErrorType::get (getASTContext ());
59065906
5907+ if (constraintType->isConstraintType ()) {
5908+ return ExistentialType::get (constraintType);
5909+ }
5910+
59075911 // TO-DO: generalize this and emit the same erorr for some P?
5908- if (!constraintType->isConstraintType ()) {
5909- // Emit a tailored diagnostic for the incorrect optional
5910- // syntax 'any P?' with a fix-it to add parenthesis.
5911- auto wrapped = constraintType->getOptionalObjectType ();
5912- if (wrapped && (wrapped->is <ExistentialType>() ||
5913- wrapped->is <ExistentialMetatypeType>())) {
5914- std::string fix;
5915- llvm::raw_string_ostream OS (fix);
5916- constraintType->print (OS, PrintOptions::forDiagnosticArguments ());
5917- diagnose (repr->getLoc (), diag::incorrect_optional_any,
5918- constraintType)
5912+ //
5913+ // Emit a tailored diagnostic for the incorrect optional
5914+ // syntax 'any P?' with a fix-it to add parenthesis.
5915+ auto wrapped = constraintType->getOptionalObjectType ();
5916+ if (wrapped && (wrapped->is <ExistentialType>() ||
5917+ wrapped->is <ExistentialMetatypeType>())) {
5918+ std::string fix;
5919+ llvm::raw_string_ostream OS (fix);
5920+ constraintType->print (OS, PrintOptions::forDiagnosticArguments ());
5921+ diagnose (repr->getLoc (), diag::incorrect_optional_any, constraintType)
59195922 .fixItReplace (repr->getSourceRange (), fix);
59205923
5921- // Recover by returning the intended type, but mark the type
5922- // representation as invalid to prevent it from being diagnosed elsewhere.
5923- repr->setInvalid ();
5924- return constraintType;
5925- }
5926-
5924+ // Recover by returning the intended type, but mark the type
5925+ // representation as invalid to prevent it from being diagnosed elsewhere.
5926+ repr->setInvalid ();
5927+ } else if (constraintType->is <ExistentialType>()) {
59275928 // Diagnose redundant `any` on an already existential type e.g. any (any P)
59285929 // with a fix-it to remove first any.
5929- if (constraintType->is <ExistentialType>()) {
5930- diagnose (repr->getLoc (), diag::redundant_any_in_existential,
5931- ExistentialType::get (constraintType))
5932- .fixItRemove (repr->getAnyLoc ());
5933- return constraintType;
5934- }
5935-
5930+ diagnose (repr->getLoc (), diag::redundant_any_in_existential,
5931+ ExistentialType::get (constraintType))
5932+ .fixItRemove (repr->getAnyLoc ());
5933+ } else {
59365934 diagnose (repr->getLoc (), diag::any_not_existential,
59375935 constraintType->isTypeParameter (), constraintType)
59385936 .fixItRemove (repr->getAnyLoc ());
5939- return constraintType;
59405937 }
59415938
5942- return ExistentialType::get ( constraintType) ;
5939+ return constraintType;
59435940}
59445941
59455942NeverNullType TypeResolver::resolveMetatypeType (MetatypeTypeRepr *repr,
0 commit comments