Skip to content

Conversation

@hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Oct 26, 2025

Going to split this into multiple PRs, but want to run CI on the whole thing first

@hamishknight hamishknight force-pushed the in-a-bind branch 2 times, most recently from 60f252c to 4a57d70 Compare November 7, 2025 14:07
@hamishknight hamishknight force-pushed the in-a-bind branch 6 times, most recently from 76dfb99 to 56ee5a5 Compare November 15, 2025 23:21
Previously we would allow these in Sema and diagnose them in SILGen,
but allowing them in Sema is unsound because it means the constraint
system ends up kicking interface type requests for declarations that
should be type-checked as part of the closure itself. Adjust the
name lookup logic to look through parent closures when detecting
invalid forward references.

For now we don't fallback to an outer result on encountering a
use-before-declaration to preserve the current behavior. I'm planning
on changing that in the next commit though.
If we encounter a variable declared after its use within a closure,
we can fallback to using an outer result if present. This matches the
behavior outside of a closure and generally seems more consistent with
the behavior we have if we also find an inner result.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

We know this is where the issue is so we ought to always produce a
concrete hole.
We know this is where the issue is so we can immediately bind to a hole,
ensuring we don't produce unnecessary downstream diagnostics from
things we can't infer.
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.
This allows the query to be consistent both during type-checking and
after.
Bindings in closures must be type-checked together with the surrounding
closure, add an assertion to make sure we don't try this. Carve out
an exception for code completion and error cases which may still kick
lazy type-checking. We ought to eventually fix up all the error cases
cases though since they imply we're leaving bits of the AST
un-type-checked.
@hamishknight
Copy link
Contributor Author

Splitting out the binding rule change into #85535

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.

1 participant