-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Improve diagnostics for generics in enum case #69055
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
Changes from 2 commits
1a5359b
7453af9
601e11d
109e138
266fa16
67694b7
49026e6
1be158a
e2c26c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8980,6 +8980,18 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags, | |
| if (ArgParams.isNull() || ArgParams.hasCodeCompletion()) | ||
| return ParserStatus(ArgParams); | ||
| } | ||
|
|
||
| // See if there are generic params. | ||
| auto genericParams = maybeParseGenericParams() | ||
| .getPtrOrNull(); | ||
| if (genericParams) { | ||
| auto param = genericParams->getParams().front()->getStartLoc(); | ||
|
||
| if (param) { | ||
| diagnose(param, diag::generic_param_cant_be_used_in_enum_case_decl); | ||
| Status.setIsParseError(); | ||
| return Status; | ||
|
||
| } | ||
| } | ||
|
|
||
| // See if there's a raw value expression. | ||
| SourceLoc EqualsLoc; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -636,3 +636,9 @@ if case nil = foo1 {} // Okay | |
| if case .none? = foo1 {} // Okay | ||
| if case nil = foo2 {} // Okay | ||
| if case .none?? = foo2 {} // Okay | ||
|
|
||
| enum EnumCaseWithGenericDeclaration { | ||
| case foo<T>(T) // expected-error {{generic signature cannot be declared in enum 'case'. did you mean to attach it to enum declaration?}} | ||
|
||
| case bar<T>(param: T) // expected-error {{generic signature cannot be declared in enum 'case'. did you mean to attach it to enum declaration?}} | ||
| case baz<T> // expected-error {{generic signature cannot be declared in enum 'case'. did you mean to attach it to enum declaration?}} | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add tests for invalid generic clause like
It seems like
maybeParseGenericParamsmay emit other diagnostics when the generic parmeters is invalid, which will be removed entirely when the generic clause is gone anyways.