-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeComplete] A couple of contextual type handling tweaks #71211
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,55 @@ struct TestSingleExprClosureGlobal { | |
// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; | ||
} | ||
|
||
struct TestSingleExprClosureBinding { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() -> Int { | ||
let fn = { | ||
self.#^TestSingleExprClosureBinding^# | ||
} | ||
return fn() | ||
} | ||
// Void is always valid in an implicit single expr closure. | ||
// TestSingleExprClosureBinding-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestSingleExprClosureBinding-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; | ||
// TestSingleExprClosureBinding-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; | ||
} | ||
|
||
struct TestExplicitSingleExprClosureBinding { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() { | ||
let fn = { | ||
return self.#^TestExplicitSingleExprClosureBinding^# | ||
} | ||
} | ||
// FIXME: Because we have an explicit return, and no expected type, we shouldn't suggest Void. | ||
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. Actually, I think suggesting values that return So, I would just remove the FIXME 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. Right, but in this case there's no contextual type. If there was an explicit 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. We could carve out an exception for 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. I think what I’m trying to say is that I don’t really care about this case because you can argue either way and I would just remove the FIXME. But if you want to keep it, that’s good with me as well. 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. Going to keep it for now since this is going to change anyway with my constraint system patch. I should also note that not suggesting Void is also the behavior we currently have for multi-statement closure returns. I don't really feel too strongly about it either way (and am happy to carve out an exception for returns if we want that), but I think we should at least be consistent there 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. Changing in #71272 |
||
// TestExplicitSingleExprClosureBinding-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestExplicitSingleExprClosureBinding-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; | ||
// TestExplicitSingleExprClosureBinding-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; | ||
} | ||
|
||
struct TestExplicitSingleExprClosureBindingWithContext { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() { | ||
let fn: () -> Void = { | ||
return self.#^TestExplicitSingleExprClosureBindingWithContext^# | ||
} | ||
} | ||
// We know Void is valid. | ||
// TestExplicitSingleExprClosureBindingWithContext-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestExplicitSingleExprClosureBindingWithContext-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; | ||
// TestExplicitSingleExprClosureBindingWithContext-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: void()[#Void#]; | ||
} | ||
|
||
struct TestNonSingleExprClosureGlobal { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
|
@@ -190,6 +239,21 @@ struct TestSingleExprFunc { | |
// TestSingleExprFunc-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; | ||
} | ||
|
||
struct TestSingleExprFuncReturnVoid { | ||
func void() -> Void {} | ||
func str() -> String { return "" } | ||
func int() -> Int { return 0 } | ||
|
||
func test() { | ||
return self.#^TestSingleExprFuncReturnVoid^# | ||
} | ||
|
||
// Void is the only possible type that can be used here. | ||
// TestSingleExprFuncReturnVoid-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; | ||
// TestSingleExprFuncReturnVoid-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; | ||
// TestSingleExprFuncReturnVoid-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: void()[#Void#]; | ||
} | ||
|
||
struct TestSingleExprFuncUnresolved { | ||
enum MyEnum { case myEnum } | ||
enum NotMine { case notMine } | ||
|
Uh oh!
There was an error while loading. Please reload this page.