Skip to content

[Sema][SR-720] Fallback to ExprPattern if enum element not found for UnresolvedDotExpr #3757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
EnumElementDecl *referencedElement
= lookupEnumMemberElement(TC, DC, ty, ude->getName().getBaseName(),
ude->getLoc());
if (!referencedElement)
return nullptr;

// Build a TypeRepr from the head of the full path.
// FIXME: Compound names.
Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/enum-with-target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let calendarUnitsDep: CalendarUnitDeprecated = [.eraCalendarUnitDeprecated, .yea
// rdar://problem/21081557
func pokeRawValue(_ random: SomeRandomEnum) {
switch (random) {
case SomeRandomEnum.RawValue // expected-error{{enum case 'RawValue' not found in type 'SomeRandomEnum'}}
case SomeRandomEnum.RawValue // expected-error{{expression pattern of type 'RawValue.Type' (aka 'Int.Type') cannot match values of type 'SomeRandomEnum'}}
// expected-error@-1{{expected ':' after 'case'}}
}
}
27 changes: 27 additions & 0 deletions test/Parse/switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,30 @@ func f0(values: [Whatever]) { // expected-note {{did you mean 'values'?}}
break
}
}

// sr-720
enum Whichever {
case Thing
static let title = "title"
static let alias: Whichever = .Thing
}
func f1(x: String, y: Whichever) {
switch x {
case Whichever.title: // Ok. Don't emit diagnostics for static member of enum.
break
case Whichever.buzz: // expected-error {{type 'Whichever' has no member 'buzz'}}
break
case Whichever.alias: // expected-error {{expression pattern of type 'Whichever' cannot match values of type 'String'}}
break
default:
break
}
switch y {
case Whichever.Thing: // Ok.
break
case Whichever.alias: // Ok. Don't emit diagnostics for static member of enum.
break
case Whichever.title: // expected-error {{expression pattern of type 'String' cannot match values of type 'Whichever'}}
break
}
}