-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[DNM] A couple of binding fixes #85141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hamishknight
wants to merge
11
commits into
swiftlang:main
Choose a base branch
from
hamishknight:in-a-bind
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f0d5da7 to
9585582
Compare
60f252c to
4a57d70
Compare
76dfb99 to
56ee5a5
Compare
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.
56ee5a5 to
1b4deb9
Compare
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.
1b4deb9 to
a83e977
Compare
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Going to split this into multiple PRs, but want to run CI on the whole thing first