Skip to content

[ConstraintSystem] Enforce TVO_CanBindToPack, and diagnose pack references outside of pack expansion expressions. #64498

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 1 commit into from
Mar 21, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 21, 2023

This changes catches the mistake of referencing a value pack without any keywords or with each outside of a pack expansion expression:

func packOutsideExpansion<each T>(_ t: repeat each T) {
  _ = t // error: pack reference 'T' can only appear in pack expansion
  _ = each t // error: pack reference 'T' can only appear in pack expansion
}

This is done by enforcing TVO_CanBindToPack when binding a type variable to a fixed type. If the binding is a PackType or a PackArchetypeType, solving the constraint will either fail, or apply a constraint fix in diagnostic mode for the invalid pack reference. During CSGen, type variables for decl refs and unresolved dot refs will be marked as TVO_CanBindToPack if there is an enclosing pack expansion expression.

This subsumes #61777

…ences outside

of pack expansion expressions.
@hborla hborla force-pushed the diagnose-pack-outside-expansion-expr branch from 23e9d69 to cb19fc3 Compare March 21, 2023 03:13
@hborla
Copy link
Member Author

hborla commented Mar 21, 2023

@swift-ci please smoke test

@@ -5317,8 +5317,9 @@ ERROR(expansion_not_allowed,none,
ERROR(expansion_not_variadic,none,
"pack expansion %0 must contain at least one pack reference", (Type))
ERROR(pack_reference_outside_expansion,none,
"pack reference %0 can only appear in pack expansion or generic requirement",
(Type))
"pack reference %0 can only appear in pack expansion "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this error message, bike-shedding is welcome!

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I will think about the diagnostic, we can always change it later.

@hborla
Copy link
Member Author

hborla commented Mar 21, 2023

@swift-ci please smoke test macOS

@hborla hborla merged commit c60b486 into swiftlang:main Mar 21, 2023
@hborla hborla deleted the diagnose-pack-outside-expansion-expr branch March 21, 2023 21:00
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.

2 participants