Skip to content

Commit 407c38e

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[typechecker] look through all optionals
1 parent 82da037 commit 407c38e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,9 +1391,10 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
13911391
// If we have an optional type, let's try to see if the case
13921392
// exists in its base type and if it does then synthesize an
13931393
// OptionalSomePattern that wraps the case.
1394-
if (auto baseType = type->getOptionalObjectType()) {
1395-
if (lookupEnumMemberElement(*this, dc, baseType, EEP->getName(),
1396-
EEP->getLoc())) {
1394+
if (type->getOptionalObjectType()) {
1395+
if (lookupEnumMemberElement(*this, dc,
1396+
type->lookThroughAllOptionalTypes(),
1397+
EEP->getName(), EEP->getLoc())) {
13971398
P = new (Context)
13981399
OptionalSomePattern(EEP, EEP->getEndLoc(), /*implicit*/true);
13991400
return coercePatternToType(P, resolution, type, options);

test/Constraints/patterns.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,14 @@ switch sr7799 {
418418
case .baz: break // Ok
419419
default: break
420420
}
421+
422+
let sr7799_1: SR_7799?? = .baz
423+
424+
switch sr7799_1 {
425+
case .bar?: break // Ok
426+
case .baz: break // Ok
427+
default: break
428+
}
429+
430+
if case .baz = sr7799_1 {} // Ok
431+
if case .bar? = sr7799_1 {} // Ok

0 commit comments

Comments
 (0)