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

View has - by default - a Body of type Never. #110

Closed
filip-sakel opened this issue Jun 22, 2020 · 1 comment
Closed

View has - by default - a Body of type Never. #110

filip-sakel opened this issue Jun 22, 2020 · 1 comment
Assignees
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI

Comments

@filip-sakel
Copy link
Contributor

filip-sakel commented Jun 22, 2020

This introduces bugs and almost defeats the purpose of compile-time errors. To prevent the program compiling successfully without producing an error for a type like Foo:

struct Foo: View {
    
}

There are two options - that I can think of:

  1. Add another _Never conditional conformances - to a dummy type like _Never that will require disambiguating when omitting the body:

    enum _Never: View {
        var body: Never { fatalError() }
    }
    
    extension View where Body == _Never {
        var body: _Never {
            fatalError("Can't access body of Never View.")
        }
    }

    That is a hack though and the error ("Type 'H' does not conform to protocol 'Block'") doesn't provide a fix possibly leaving a novice developer confused.

  2. Remove the extension that provides an automatic conformance when Body is of type Never and move that behaviour to the ViewDeferredToRenderer protocol - or to an underlying view protocol such as _StuctureView, _View, _FatalView:

    protocol _StuctureView: View where Body == Never {}
    
    extension _StuctureView {
         var body: Never {
            fatalError("Can't access body of Structure View.")
        }
    }

    That IMO is the best option, as it avoids automatic type-inference altogether and provides a useful error message - that offers a fix.

@MaxDesiatov MaxDesiatov added the SwiftUI compatibility Tokamak API differences with SwiftUI label Jun 22, 2020
@MaxDesiatov MaxDesiatov self-assigned this Jun 22, 2020
@MaxDesiatov
Copy link
Collaborator

Thank you @filip-sakel, this is a great point, primarily because it also highlights the incompatibility with SwiftUI, it is now fixed in the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI
Development

No branches or pull requests

2 participants