|
17 | 17 |
|
18 | 18 | #include "TypeChecker.h"
|
19 | 19 | #include "GenericTypeResolver.h"
|
| 20 | +#include "swift/Basic/StringExtras.h" |
20 | 21 | #include "swift/AST/ExprHandle.h"
|
21 | 22 | #include "swift/AST/ASTWalker.h"
|
22 | 23 | #include "swift/AST/ASTVisitor.h"
|
@@ -1384,9 +1385,29 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
|
1384 | 1385 | if (type->getAnyNominal())
|
1385 | 1386 | elt = lookupEnumMemberElement(*this, dc, type, EEP->getName());
|
1386 | 1387 | if (!elt) {
|
1387 |
| - if (!type->is<ErrorType>()) |
| 1388 | + if (!type->is<ErrorType>()) { |
| 1389 | + // Lowercasing of Swift.Optional's cases is handled in the |
| 1390 | + // standard library itself, not through the clang importer, |
| 1391 | + // so we have to do this check here. Additionally, .Some |
| 1392 | + // isn't a static VarDecl, so the existing mechanics in |
| 1393 | + // extractEnumElement won't work. |
| 1394 | + if (type->getAnyNominal() == Context.getOptionalDecl()) { |
| 1395 | + if (EEP->getName().str() == "None" || |
| 1396 | + EEP->getName().str() == "Some") { |
| 1397 | + SmallString<4> Rename; |
| 1398 | + camel_case::toLowercaseWord(EEP->getName().str(), Rename); |
| 1399 | + diagnose(EEP->getLoc(), diag::availability_decl_unavailable_rename, |
| 1400 | + EEP->getName(), /*replaced*/false, |
| 1401 | + /*special kind*/0, Rename.str()) |
| 1402 | + .fixItReplace(EEP->getLoc(), Rename.str()); |
| 1403 | + |
| 1404 | + } |
| 1405 | + return true; |
| 1406 | + } |
| 1407 | + |
1388 | 1408 | diagnose(EEP->getLoc(), diag::enum_element_pattern_member_not_found,
|
1389 | 1409 | EEP->getName().str(), type);
|
| 1410 | + } |
1390 | 1411 | return true;
|
1391 | 1412 | }
|
1392 | 1413 | enumTy = type;
|
|
0 commit comments