Skip to content

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Aug 22, 2025

  • Introduce a generic requirements opening function for type resolution, which is used by the constraint system in cases where we need to impose requirements on opened type variables.
  • Refactor replaceInferableTypesWithTypeVars to use this function when opening generic types that contain either placeholder or unbound generic types.

Together these changes ensure that we don't drop generic requirements when an unbound generic or placeholder type is used as a generic argument.

rdar://154857586
Resolves #82722

@hamishknight hamishknight force-pushed the overrun branch 2 times, most recently from b4adeff to d321ed0 Compare August 25, 2025 23:19
@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@hamishknight
Copy link
Contributor Author

@swift-ci please SourceKit stress test

Requirement opening relies on being able to query the opened type to
allow requirement fix coalescing to work. Record the opened type before
we open requirements to ensure we don't duplicate requirement fixes on
the base type with requirement fixes for the member.
@hamishknight hamishknight changed the title [WIP] [CS] Open generic requirements for types with unbound + placeholder types [CS] Open generic requirements for types with unbound + placeholder types Aug 26, 2025
@hamishknight hamishknight marked this pull request as ready for review August 26, 2025 10:07
…ypes

- Introduce a generic requirements opening function for type resolution,
  which is used by the constraint system in cases where we need to
  impose requirements on opened type variables.
- Refactor `replaceInferableTypesWithTypeVars` to use this function
  when opening generic types that contain either placeholder or unbound
  generic types.

Together these changes ensure that we don't drop generic requirements
when an unbound generic or placeholder type is used as a generic
argument.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

Comment on lines +3422 to +3429
// In principle we shouldn't need to open the generic parameters here, we
// could just open the requirements using the substituted arguments directly,
// but that doesn't allow us to correctly handle requirement fix coalescing
// in `isFixedRequirement`. So instead we open the generic parameters and
// then bind the resulting type variables to the substituted args.
SmallVector<OpenedType, 4> replacements;
cs.openGenericParameters(outerDC, sig, replacements, locator,
preparedOverload);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alternative approach here would be adjusting getTypeOfMemberReference to avoid opening requirements that are already imposed by the base type (b4adeff), but that needs a workaround for at least LLDB, and generally seems like it could be more error prone. Given we need to fix the locators here anyway to be unique, this seems like the simplest way of avoiding the duplicate diagnostics

@hamishknight hamishknight merged commit 9c89820 into swiftlang:main Aug 27, 2025
5 checks passed
@hamishknight hamishknight deleted the overrun branch August 27, 2025 22:20
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.

Invalid conformance in type-checked AST

2 participants