-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Variadic Generics] distinctly diagnose more types of pack expansion errors #64447
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
[Variadic Generics] distinctly diagnose more types of pack expansion errors #64447
Conversation
include/swift/Basic/SourceLoc.h
Outdated
@@ -157,7 +157,7 @@ class SourceRange { | |||
/// A half-open character-based source range. | |||
class CharSourceRange { | |||
SourceLoc Start; | |||
unsigned ByteLength; | |||
unsigned ByteLength{}; |
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.
Why this change?
@@ -5310,8 +5310,8 @@ ERROR(vararg_not_allowed,none, | |||
"variadic parameter cannot appear outside of a function parameter list", | |||
()) | |||
ERROR(expansion_not_allowed,none, | |||
"pack expansion %0 cannot appear outside of a function parameter list, " | |||
"function result, tuple element or generic argument list", (Type)) | |||
"pack expansion repeat each %0 can only appear in a function parameter list, " |
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.
Instead of writing 'repeat each' in the diagnostic, which looks funny: repeat each 'T'
, can you create a PackExpansionType and pass it as %0 to the diagnostic? Then it will say 'repeat each T'
a0e20e3
to
64461f0
Compare
// expected-error@+1 {{pack expansion 'Int' must contain at least one pack reference}} | ||
func invalidPackRefRepeatInt(_: repeat Int) {} | ||
|
||
// expected-error@+1 {{pack reference 'T' requires expansion using keyword 'repeat'}} | ||
func packRefOutsideExpansion<each T>(_: each T) {} |
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.
A few more to test:
func packRefOutsideExpansion<each T>(_: Array<each T>) {}
func packRefOutsideExpansion<each T>(_: Array<(each T) -> ()>) {}
func packRefOutsideExpansion<each T>(_: (each T)) {}
func packRefOutsideExpansion<each T>(_: each T.Type) {}
…errors + add fixits
17656ed
to
19e671b
Compare
@swift-ci please smoke test |
No description provided.