Skip to content

Conversation

@hamishknight
Copy link
Contributor

I'm planning on adding an assert that ensures we don't type-check bindings independently of their closure context, the fuzzer found crashers for the following cases, which with some modification can also crash even without the assert. Fix up these cases such that we can land the assert without regressing anything.

  • Better handle recovery for structurally invalid ReturnStmts such that we still type-check the result expression
  • Invalidate unresolved variables in ExprPatterns early in CSGen to ensure we don't generate constraints for a where clause before we've assigned them a type
  • Remove a redundant ErrorExpr check from ASTScopes

Make sure we don't produce unnecessary diagnostics while still allowing
things like cursor info to work. No test change since it's covered by
the next commit.
Make sure we preserve the result expression for an out-of-place
`return`, or a non-`nil` result in an initializer. This ensures we
can still provide semantic functionality from them and fixes a crash
where we would fail to type-check a binding.
Make sure we invalidate when we initially visit the ExprPattern to
ensure that we don't run into issues when generating constraints for
a `where` clause before the constraints for the ExprPattern. We ought
to change the constraint generation there to use a conjunction to
ensure that the pattern is solved before the `where` clause, but I
want to keep this as a quick low risk fix that we can cherry-pick. I'll
switch it to a conjunction in a follow-up.
This appears unnecessary and incorrectly meant the ErrorExpr would
be placed outside the condition, meaning we could find the binding
in its own initializer.
@hamishknight
Copy link
Contributor Author

@swift-ci please test macOS

@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test Linux

@hamishknight
Copy link
Contributor Author

swiftlang/swift-docc#1352

@swift-ci please test Windows

@hamishknight hamishknight merged commit 4992c7a into swiftlang:main Nov 18, 2025
6 checks passed
@hamishknight hamishknight deleted the binding-fixes branch November 18, 2025 19:48
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