Skip to content
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

[SR-12847] Function Builder with return statements produces confusing and erroneous diagnostic #55293

Open
NachoSoto opened this issue May 20, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation result builders Feature: Result builders

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-12847
Radar rdar://problem/63610269
Original Reporter @NachoSoto
Type Bug
Environment

Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, FunctionBuilder
Assignee None
Priority Medium

md5: 8b107381b04ea5bf82062c3cda810120

Issue Description:

The first that came to mind when I was struggling with this was this tweet: https://twitter.com/javi/status/1262381836614893568?s=21.

Consider this seemingly normal code:

struct WTF: View {
    var body: some View {
        Group {
            if Bool.random {
                return Circle()
            } else {
                return Rectangle()
            }
        }
    }
}

This produces this error, with a bogus fixit:

error: generic parameter 'Content' could not be inferred
                Group {
                ^
note: explicitly specify the generic arguments to fix this issue
                Group {
                ^
                     <Any>

The actual error is those `return` statements, but that's not intuitive at all, and the error doesn't help one bit.
The underlying issue is that function builders lead us to believe we're writing regular code with closures, but they're full of these paper cuts.

@theblixguy
Copy link
Collaborator

On master, I get:

error: unable to infer complex closure return type; add explicit type to disambiguate
                Group {
                      ^
                        () -> <#Result#> in

@xedin
Copy link
Member

xedin commented May 26, 2020

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation result builders Feature: Result builders
Projects
None yet
Development

No branches or pull requests

3 participants