-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unified: Basic support for extensions #22558
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8d48ea1
unified: Add simple extension-method test
asgerf fcda162
unified: Add extension_target field and use it
asgerf 6ce06bf
unified: Regenerate QL
asgerf 4c22372
unified: Update test after extractor change
asgerf 29a33cc
unified: Include extensions in namespace of target class
asgerf b60ac25
unified: Handle unqualified member access inside extension
asgerf 6490d2d
unified: Add test with inheritance resolved through extension
asgerf a195458
unified: Ensure static namespace is available in graph
asgerf 21b5ebb
unified: Add test with inheritance through extension
asgerf 281cd00
unified: Update corpus test output
asgerf fb14563
unified: Fix comment
asgerf ffdd2a4
unified: Include extension steps in debug view
asgerf e5034d9
unified: Update test case to be valid Swift
asgerf 5bbae07
unified: Add tests for missing features
asgerf f5be544
unified: Test protocol method with and without implementation
asgerf 22ae803
unified: Add test for "default implementation" pattern
asgerf 1b72559
unified: Add comment regarding local namespace in an extension
asgerf 432f8c0
unified: Add comment clarifying case with multiple targets
asgerf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
79 changes: 79 additions & 0 deletions
79
unified/ql/test/library-tests/static-name-binding/extensions.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| class A { | ||
| func ownMethod() { | ||
| ownMethod() // $ access=A.ownMethod | ||
| extensionMethod1() // $ access=A.extensionMethod1 | ||
| extensionMethod2() // $ access=A.extensionMethod2 | ||
| } | ||
| } | ||
|
|
||
| extension A { // $ access=A | ||
| func extensionMethod1() { // name=A.extensionMethod1 | ||
| ownMethod() // $ access=A.ownMethod | ||
| extensionMethod1() // $ access=A.extensionMethod1 | ||
| extensionMethod2() // $ access=A.extensionMethod2 | ||
| } | ||
| } | ||
|
|
||
| extension A { // $ access=A | ||
| func extensionMethod2() { // name=A.extensionMethod2 | ||
| ownMethod() // $ access=A.ownMethod | ||
| extensionMethod1() // $ access=A.extensionMethod1 | ||
| extensionMethod2() // $ access=A.extensionMethod2 | ||
| } | ||
| } | ||
|
|
||
| class B { | ||
| } | ||
|
|
||
| extension B { // $ access=B | ||
| class C { // name=B.C | ||
| class D {} // name=B.C.D | ||
| } | ||
| } | ||
| extension B { // $ access=B | ||
| class Nested : C { // $ access=B.C | ||
| let x : D // $ access=B.C.D | ||
| } | ||
| } | ||
|
|
||
| // Protocol conformance through extension | ||
| protocol Base { | ||
| func baseMethod(); | ||
| func baseMethodNoImpl(); | ||
| func baseMethodDefaultImpl(); | ||
| } | ||
| extension Base { // $ access=Base | ||
| func baseMethodExt() {} // name=BaseImpl.baseMethodExt | ||
| func baseMethodDefaultImpl() {} // name=BaseImpl.baseMethodDefaultImpl | ||
| } | ||
| class X { | ||
| func xMethod() { | ||
| baseMethod() // $ access=X.baseMethod | ||
| baseMethodNoImpl() // $ access=Base.baseMethodNoImpl // with no visible implementation, just resolve to the signature | ||
| baseMethodExt() // $ access=BaseImpl.baseMethodExt | ||
|
|
||
| // Static name binding may find multiple targets. Type inference should disambiguate. | ||
| baseMethodDefaultImpl() // $ access=Base.baseMethodDefaultImpl access=BaseImpl.baseMethodDefaultImpl | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the last access be marked as spurious?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment to clarify, based on offline discussion |
||
| } | ||
| } | ||
|
|
||
| extension X : Base { // $ access=X access=Base | ||
| func baseMethod() {} // name=X.baseMethod | ||
| } | ||
|
|
||
| class Y { | ||
| func yMethod() { | ||
| baseMethod() // $ access=Y.baseMethod | ||
| baseMethodDefaultImpl() // $ access=Y.baseMethodDefaultImpl | ||
| } | ||
| } | ||
| extension Y : Base { // $ access=Y access=Base | ||
| func baseMethod() {} // name=Y.baseMethod | ||
| func baseMethodDefaultImpl() {} // name=Y.baseMethodDefaultImpl | ||
| } | ||
|
|
||
|
hvitved marked this conversation as resolved.
|
||
| // Type parameters of the extended type should be in scope in the extension. | ||
| class GenericExtensionTarget<ExtensionTypeParameter> {} | ||
| extension GenericExtensionTarget { // $ access=GenericExtensionTarget | ||
| func useTypeParameter(_: ExtensionTypeParameter) {} // $ MISSING: access=ExtensionTypeParameter | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
unified/ql/test/library-tests/static-name-binding/package1/Sources/Target1/File1.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| let x: A; // $ access=Target1.A | ||
| let y: Target2.A; // not a valid reference | ||
|
|
||
| public class ScopedExtensionTarget { | ||
| func useExtensionFromUnimportedModule() { | ||
| target2ExtensionMethod() // $ SPURIOUS: access=Target1.ScopedExtensionTarget.target2ExtensionMethod | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
unified/ql/test/library-tests/static-name-binding/package1/Sources/Target2/File3.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import Target1 | ||
|
|
||
| public class A {} // name=Target2.A | ||
|
|
||
| public class B { // name=Target2.B | ||
| public class C {} // name=Target2.B.C | ||
| } | ||
|
|
||
| extension ScopedExtensionTarget { // $ access=ScopedExtensionTarget | ||
| func target2ExtensionMethod() {} // name=Target1.ScopedExtensionTarget.target2ExtensionMethod | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.