Open swift-ci opened 3 years ago
@swift-ci create
Type-checker would produce expected solution if second closure were to specify a parameter e.g. '.foo { $0 }.foo { _ in true }', otherwise `E` from `TransformB` gets defaulted to `Void` because it's the only valid solution here for second closure to be of type `(()) -> Bool`.
Comment by Rongxin Shan (JIRA)
Thanks for your explanation.
But I think the code in second closure make the logic of first closure be unexpected, this may be confusing.
Here could be a common situation: e.g
//代码占位符
struct Data { }
let arr = [1, nil, 2, 6]
let mappedArr = arr.compactMap{ $0 }.map{ Data() } // result: [Data, Data, Data, Data]
Or maybe compiler can throws a better diagnostic ?
Look forward to your reply. Thanks. @xedin
shanrongxin@bytedance.com (JIRA User) We can't change the behavior (e.g. to fail and produce a diagnostic) without source compatibility impact so our hands are tied here unfortunately.
Attachment: Download
Environment
Xcode Version 12.4 (12D4e) Max OS X: 10.15.7 (19H524) Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28) Target: x86_64-apple-darwin19.6.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | shanrongxin@bytedance.com (JIRA) | |Priority | Medium | md5: a0eff88e2eaf2eda0d7c1ced779797dcIssue Description:
{$0} (which explicit argument is Int) is inferred to type (Int) -> () instead of (Int) -> (Int) on a specific situation . (actually there is a warning, but it should to be an error )
when use swiftc -dump ast
playground file is in attachment
Thanks !