@@ -5904,42 +5904,39 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
5904
5904
if (constraintType->hasError ())
5905
5905
return ErrorType::get (getASTContext ());
5906
5906
5907
+ if (constraintType->isConstraintType ()) {
5908
+ return ExistentialType::get (constraintType);
5909
+ }
5910
+
5907
5911
// 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)
5919
5922
.fixItReplace (repr->getSourceRange (), fix);
5920
5923
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>()) {
5927
5928
// Diagnose redundant `any` on an already existential type e.g. any (any P)
5928
5929
// 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 {
5936
5934
diagnose (repr->getLoc (), diag::any_not_existential,
5937
5935
constraintType->isTypeParameter (), constraintType)
5938
5936
.fixItRemove (repr->getAnyLoc ());
5939
- return constraintType;
5940
5937
}
5941
5938
5942
- return ExistentialType::get ( constraintType) ;
5939
+ return constraintType;
5943
5940
}
5944
5941
5945
5942
NeverNullType TypeResolver::resolveMetatypeType (MetatypeTypeRepr *repr,
0 commit comments