-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[code-completion] Add type context for single-expression closures #23411
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
4 commits
Select commit
Hold shift + click to select a range
b817cbb
[code-completion] Add type context for single-expression closures
benlangmuir f8a3afb
Fix lifetime of type context in result builder
benlangmuir 2b5a8a5
Fix assertion failure in validation test
benlangmuir b512ab2
Add tests for non-single-expression closures and remove dead code
benlangmuir 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureRet | %FileCheck %s -check-prefix=TestSingleExprClosureRet | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureRetVoid | %FileCheck %s -check-prefix=TestSingleExprClosureRetVoid | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureRetUnresolved | %FileCheck %s -check-prefix=TestSingleExprClosureRetUnresolved | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosure | %FileCheck %s -check-prefix=TestSingleExprClosure | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureVoid | %FileCheck %s -check-prefix=TestSingleExprClosureRetVoid | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureUnresolved | %FileCheck %s -check-prefix=TestSingleExprClosureRetUnresolved | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureCall | %FileCheck %s -check-prefix=TestSingleExprClosure | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureGlobal | %FileCheck %s -check-prefix=TestSingleExprClosureGlobal | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestNonSingleExprClosureGlobal | %FileCheck %s -check-prefix=TestNonSingleExprClosureGlobal | ||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestNonSingleExprClosureUnresolved | %FileCheck %s -check-prefix=TestNonSingleExprClosureUnresolved | ||
|
||
struct TestSingleExprClosureRet { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() -> Int { | ||
return { () in | ||
return self.#^TestSingleExprClosureRet^# | ||
}() | ||
} | ||
|
||
// TestSingleExprClosureRet: Begin completions | ||
// TestSingleExprClosureRet-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestSingleExprClosureRet-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: int()[#Int#]; | ||
// TestSingleExprClosureRet-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: void()[#Void#]; | ||
// TestSingleExprClosureRet: End completions | ||
} | ||
|
||
struct TestSingleExprClosureRetVoid { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() { | ||
return { () in | ||
return self.#^TestSingleExprClosureRetVoid^# | ||
}() | ||
} | ||
|
||
// TestSingleExprClosureRetVoid: Begin completions | ||
// TestSingleExprClosureRetVoid-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestSingleExprClosureRetVoid-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; | ||
// TestSingleExprClosureRetVoid-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: void()[#Void#]; | ||
// TestSingleExprClosureRetVoid: End completions | ||
} | ||
|
||
struct TestSingleExprClosureRetUnresolved { | ||
enum MyEnum { case myEnum } | ||
enum NotMine { case notMine } | ||
func mine() -> MyEnum { return .myEnum } | ||
func notMine() -> NotMine { return .notMine } | ||
|
||
func test() -> MyEnum { | ||
return { () in | ||
return .#^TestSingleExprClosureRetUnresolved^# | ||
}() | ||
} | ||
|
||
// TestSingleExprClosureRetUnresolved: Begin completions | ||
// TestSingleExprClosureRetUnresolved-NOT: notMine | ||
// TestSingleExprClosureRetUnresolved: Decl[EnumElement]/ExprSpecific: myEnum[#TestSingleExprClosure{{(Ret)?}}Unresolved.MyEnum#]; | ||
// TestSingleExprClosureRetUnresolved-NOT: notMine | ||
// TestSingleExprClosureRetUnresolved: End completions | ||
} | ||
|
||
struct TestSingleExprClosure { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() -> Int { | ||
return { () in | ||
self.#^TestSingleExprClosure^# | ||
}() | ||
} | ||
// TestSingleExprClosure: Begin completions | ||
// TestSingleExprClosure-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestSingleExprClosure-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: int()[#Int#]; | ||
// NOTE: this differs from the one using a return keyword. | ||
// TestSingleExprClosure-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; | ||
// TestSingleExprClosure: End completions | ||
} | ||
|
||
struct TestSingleExprClosureVoid { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() { | ||
return { () in | ||
self.#^TestSingleExprClosureVoid^# | ||
}() | ||
} | ||
} | ||
|
||
struct TestSingleExprClosureUnresolved { | ||
enum MyEnum { case myEnum } | ||
enum NotMine { case notMine } | ||
func mine() -> MyEnum { return .myEnum } | ||
func notMine() -> NotMine { return .notMine } | ||
|
||
func test() -> MyEnum { | ||
return { () in | ||
.#^TestSingleExprClosureUnresolved^# | ||
}() | ||
} | ||
} | ||
|
||
struct TestSingleExprClosureCall { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func take(_: () -> Int) {} | ||
|
||
func test() { | ||
take { | ||
self.#^TestSingleExprClosureCall^# | ||
} | ||
} | ||
} | ||
|
||
struct TestSingleExprClosureGlobal { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() -> Int { | ||
return { () in | ||
#^TestSingleExprClosureGlobal^# | ||
}() | ||
} | ||
// TestSingleExprClosureGlobal: Begin completions | ||
// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: str()[#String#]; | ||
// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal/TypeRelation[Identical]: int()[#Int#]; | ||
// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: void()[#Void#]; | ||
// TestSingleExprClosureGlobal: End completions | ||
} | ||
|
||
struct TestNonSingleExprClosureGlobal { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() -> Int { | ||
return { () in | ||
#^TestNonSingleExprClosureGlobal^# | ||
return 42 | ||
}() | ||
} | ||
// TestNonSingleExprClosureGlobal: Begin completions | ||
// TestNonSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: str()[#String#]; | ||
// TestNonSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: int()[#Int#]; | ||
// TestNonSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: void()[#Void#]; | ||
// TestNonSingleExprClosureGlobal: End completions | ||
} | ||
|
||
struct TestNonSingleExprClosureUnresolved { | ||
enum MyEnum { case myEnum } | ||
enum NotMine { case notMine } | ||
func mine() -> MyEnum { return .myEnum } | ||
func notMine() -> NotMine { return .notMine } | ||
|
||
func test() -> Int { | ||
return { () in | ||
.#^TestNonSingleExprClosureUnresolved^# | ||
return 42 | ||
}() | ||
} | ||
// TestNonSingleExprClosureUnresolved-NOT: myEnum | ||
// TestNonSingleExprClosureUnresolved-NOT: notMine | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xedin FYI
Avoids assertion failure:
https://ci.swift.org/job/swift-PR-osx/11875/consoleFull#-1251633450ef3c3c00-f496-40b9-85a7-0eb69d0f491b