Skip to content

Conversation

jmschonfeld
Copy link
Contributor

@jmschonfeld jmschonfeld commented Aug 27, 2025

KeyPaths used in predicates with a computed component can contain two types of arguments:

  1. Concrete values passed as parameters to subscripts
  2. Generic arguments used to satisfy generic constraints of a property

Predicate can support generic arguments, but not concrete values passed to subscripts (the subscript predicate expression should be used instead). When originally writing this code, I had conflated the two concepts as one and introduced the restrictArguments flag to work around cases where code accidentally asserted eagerly for only generic arguments. However, I also accidentally defaulted the argument to false so the assertion never ran. As part of #1476 I set the default value to true correcting this mistake. Unfortunately, since the assertion conflates the two types of arguments, the assertion trips incorrectly in some existing client code (Predicates created where the root type is generic and therefore property access provides a generic argument in the key path). For now, to fix this regression, this removes the restrictArguments parameter and removes the assertion altogether. In the long term, we should followup with a fix that adds this assertion back with improved validation logic not based on a restrictArguments parameter but rather based on other contents in the keypath to distinguish between the two types of arguments (tracked by #1482 - I think this is something we should do as a followup since its implementation requires more testing and either requires a new C shim or some even more hacky workarounds).

rdar://159210502

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld merged commit 081798c into swiftlang:main Aug 27, 2025
19 checks passed
@jmschonfeld jmschonfeld deleted the predicate-generic-keypath-crash branch August 27, 2025 19:41
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