Skip to content

[Sema] Avoid null-node crash for invalid closure parameter wrappers#87494

Open
Flamki wants to merge 1 commit intoswiftlang:mainfrom
Flamki:fix-87479-closure-wrapper-null-node
Open

[Sema] Avoid null-node crash for invalid closure parameter wrappers#87494
Flamki wants to merge 1 commit intoswiftlang:mainfrom
Flamki:fix-87479-closure-wrapper-null-node

Conversation

@Flamki
Copy link
Contributor

@Flamki Flamki commented Feb 25, 2026

Summary

This fixes an assertion crash when a closure parameter uses an invalid property wrapper.

For code like:

@propertyWrapper
struct A {}

let c = { (@A x) in
  return x
}

the compiler was asserting in ConstraintSystem::setType because closure wrapper-synthesized vars could be missing, but resolveClosure unconditionally attempted to assign types to them.

What changed

  • In ConstraintSystem::resolveClosure (lib/Sema/CSSimplify.cpp):
    • Guard use of closure wrapper-synthesized vars (backingVar, wrappedValueVar).
    • Only run wrapper-specific type assignment and wrapper constraints when those vars are present.
  • In applySolutionToClosurePropertyWrappers (lib/Sema/CSSyntacticElement.cpp):
    • Guard interface type assignment for wrapper vars the same way.
  • Added regression coverage in test/Sema/property_wrapper_parameter_invalid.swift for Usage of property wrapper in global closure parameter causes assertion failure #87479.

Why this approach

Invalid wrapper declarations are already diagnosed by declaration checking. In this path we only need to avoid crashing while closure constraints are being resolved/applied.

Before / After

Before:

  • Assertion failure during type checking (Cannot set type information on null node).

After:

  • No null-node assignment in closure wrapper handling when synthesized vars are missing.
  • Existing wrapper diagnostic is preserved, and regression coverage is added.

Issue

Fixes #87479

Invalid property wrapper declarations on closure parameters can leave wrapper-synthesized local vars absent. Avoid assigning types to missing wrapper vars during closure constraint resolution and solution application, and skip wrapper-specific constraint generation in that case.\n\nAdd a regression test for swiftlang#87479 covering a global closure parameter annotated with an invalid property wrapper.
@Flamki
Copy link
Contributor Author

Flamki commented Mar 2, 2026

@xedin Friendly ping on this when you have a moment.

This PR fixes #87479 (null-node crash with invalid closure parameter wrappers), and required checks are still in “Waiting for status to be reported”.

If it looks good, could someone trigger Swift CI for it?

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.

Usage of property wrapper in global closure parameter causes assertion failure

1 participant