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

Subclass initializer parameters don’t inherit result builder attributes #60953

Open
beccadax opened this issue Sep 5, 2022 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself result builders Feature: Result builders type checker Area → compiler: Semantic analysis

Comments

@beccadax
Copy link
Contributor

beccadax commented Sep 5, 2022

Describe the bug

If a class has an initializer with a parameter that has a result builder on it, subclasses which inherit that initializer won’t have the result builder attribute on the parameter.

Steps To Reproduce

import SwiftUI

class Super {
    init<V: View>(@ViewBuilder body: () -> V) {}
}

class Sub: Super {
    // Empty
}

func fn() {
    _ = Sub {    // error: type ‘()’ cannot conform to ‘View’
        Text("Hello")
        Text("World!")
    }
}

Expected behavior

Sub.init(body:) would have @ViewBuilder on its parameter, so ViewBuilder would be applied to the closure and the code would typecheck.

Environment (please fill out the following information)

Seen in:

  • Xcode 13.4.1 (13F100)
  • Swift Playgrounds 4.1 (1676.15)

Additional context

We originally saw this with a simple custom result builder using a variadic buildBlock, so it’s not specific to @ViewBuilder.

Thanks to @quephird for showing me this bug.

@beccadax beccadax added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. type checker Area → compiler: Semantic analysis result builders Feature: Result builders labels Sep 5, 2022
@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler itself label Dec 13, 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 itself result builders Feature: Result builders type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants