-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[DNM] Fix top level script mode vars #86111
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
10
commits into
swiftlang:main
Choose a base branch
from
hamishknight:scripted
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
+903
−598
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
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.
Contributor
Author
|
Doubt this will have much coverage, but let's see @swift-ci please test source compatibility |
FileCheck was matching against its own CHECK lines in the diagnostic output here so the test always succeeded. Convert to using the diagnostic verifier now we have `-verify-additional-prefix`.
This is no longer experimental and is the default.
not even close to complete
21002f2 to
3ae8bd4
Compare
Contributor
Author
|
@swift-ci please test source compatibility |
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.
Enforce that a PatternBindingDecl always shares the same DeclContext as any VarDecls it binds. Then change top level vars in script mode such that they are treated as local vars unless you add an access control keyword. The implementation is pretty hacked together and a lot more test cases need updating, but interested to see what the source compatibility impact is.