Skip to content

[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

Merged

Conversation

sophiapoirier
Copy link
Contributor

No description provided.

@@ -157,7 +157,7 @@ class SourceRange {
/// A half-open character-based source range.
class CharSourceRange {
SourceLoc Start;
unsigned ByteLength;
unsigned ByteLength{};
Copy link
Contributor

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, "
Copy link
Contributor

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'

@sophiapoirier sophiapoirier force-pushed the pack_expansion_error_clarity branch from a0e20e3 to 64461f0 Compare March 17, 2023 23:01
// 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) {}
Copy link
Contributor

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) {}

@sophiapoirier sophiapoirier force-pushed the pack_expansion_error_clarity branch from 17656ed to 19e671b Compare March 20, 2023 22:52
@sophiapoirier
Copy link
Contributor Author

@swift-ci please smoke test

@sophiapoirier sophiapoirier merged commit 8648753 into swiftlang:main Mar 21, 2023
@sophiapoirier sophiapoirier deleted the pack_expansion_error_clarity branch March 21, 2023 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants