Skip to content

Conversation

@hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Oct 26, 2025

depends on #85535

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 which may still kick lazy type-checking, in such cases we can just decline to type-check.

@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 8 times, most recently from 1b4deb9 to a83e977 Compare November 16, 2025 16:59
@hamishknight
Copy link
Contributor Author

Splitting out the binding rule change into #85535

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.

rdar://74430478
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.

rdar://163656720
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

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@hamishknight hamishknight changed the title [DNM] A couple of binding fixes [Sema] Enforce we don't type-check bindings independently of closures Nov 21, 2025
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