Skip to content

Commit 78b1e96

Browse files
committed
Optional case lowercase cleanups
- Use == operator for identifier comparison - Add a test where the Optional isn't the top-level type rdar://problem/26481304
1 parent efd65aa commit 78b1e96

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,9 +1396,14 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
13961396
}
13971397
if (!elt) {
13981398
if (!type->is<ErrorType>()) {
1399+
// Lowercasing of Swift.Optional's cases is handled in the
1400+
// standard library itself, not through the clang importer,
1401+
// so we have to do this check here. Additionally, .Some
1402+
// isn't a static VarDecl, so the existing mechanics in
1403+
// extractEnumElement won't work.
13991404
if (type->getAnyNominal() == Context.getOptionalDecl()) {
1400-
if (EEP->getName().str().compare("None") == 0 ||
1401-
EEP->getName().str().compare("Some") == 0) {
1405+
if (EEP->getName().str() == "None" ||
1406+
EEP->getName().str() == "Some") {
14021407
SmallString<4> Rename;
14031408
camel_case::toLowercaseWord(EEP->getName().str(), Rename);
14041409
diagnose(EEP->getLoc(), diag::availability_decl_unavailable_rename,

test/1_stdlib/OptionalRenames.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@ switch x {
1414
case .Some(let x): print(x) // expected-error {{'Some' has been renamed to 'some'}} {{9-13=some}}
1515
}
1616

17+
let optionals: (Int?, Int?) = (Optional.Some(1), .None)
18+
// expected-error@-1 {{'Some' has been renamed to 'some'}} {{41-45=some}}
19+
// expected-error@-2 {{'None' has been renamed to 'none'}} {{51-55=none}}
20+
21+
switch optionals {
22+
case (.None, .none): break // expected-error {{'None' has been renamed to 'none'}} {{10-14=none}}
23+
case (.Some(let left), .some(let right)): break // expected-error {{'Some' has been renamed to 'some'}} {{10-14=some}}
24+
default: break
25+
}
26+

0 commit comments

Comments
 (0)