Skip to content

Commit 45df1ad

Browse files
authored
Merge pull request #3757 from rintaro/SR-720-enum-static-member-pattern
[Sema][SR-720] Fallback to ExprPattern if enum element not found for UnresolvedDotExpr
2 parents 0b04c0c + 4079d7e commit 45df1ad

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
454454
EnumElementDecl *referencedElement
455455
= lookupEnumMemberElement(TC, DC, ty, ude->getName().getBaseName(),
456456
ude->getLoc());
457+
if (!referencedElement)
458+
return nullptr;
457459

458460
// Build a TypeRepr from the head of the full path.
459461
// FIXME: Compound names.

test/ClangModules/enum-with-target.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let calendarUnitsDep: CalendarUnitDeprecated = [.eraCalendarUnitDeprecated, .yea
1414
// rdar://problem/21081557
1515
func pokeRawValue(_ random: SomeRandomEnum) {
1616
switch (random) {
17-
case SomeRandomEnum.RawValue // expected-error{{enum case 'RawValue' not found in type 'SomeRandomEnum'}}
17+
case SomeRandomEnum.RawValue // expected-error{{expression pattern of type 'RawValue.Type' (aka 'Int.Type') cannot match values of type 'SomeRandomEnum'}}
1818
// expected-error@-1{{expected ':' after 'case'}}
1919
}
2020
}

test/Parse/switch.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,30 @@ func f0(values: [Whatever]) { // expected-note {{did you mean 'values'?}}
279279
break
280280
}
281281
}
282+
283+
// sr-720
284+
enum Whichever {
285+
case Thing
286+
static let title = "title"
287+
static let alias: Whichever = .Thing
288+
}
289+
func f1(x: String, y: Whichever) {
290+
switch x {
291+
case Whichever.title: // Ok. Don't emit diagnostics for static member of enum.
292+
break
293+
case Whichever.buzz: // expected-error {{type 'Whichever' has no member 'buzz'}}
294+
break
295+
case Whichever.alias: // expected-error {{expression pattern of type 'Whichever' cannot match values of type 'String'}}
296+
break
297+
default:
298+
break
299+
}
300+
switch y {
301+
case Whichever.Thing: // Ok.
302+
break
303+
case Whichever.alias: // Ok. Don't emit diagnostics for static member of enum.
304+
break
305+
case Whichever.title: // expected-error {{expression pattern of type 'String' cannot match values of type 'Whichever'}}
306+
break
307+
}
308+
}

0 commit comments

Comments
 (0)