Last active
October 9, 2020 00:53
-
-
Save kylebshr/72e45453f29695566b0eded4f70d3b9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol MyProtocol {} | |
struct MyImplemention: MyProtocol {} | |
struct MyStruct { | |
func emptyView() -> some MyProtocol { | |
MyImplemention() | |
} | |
func someView<T>(_ view: T) -> some MyProtocol where T: MyProtocol { | |
MyImplemention() | |
} | |
// Error: Function declares an opaque return type, but the return statements in its body do not have matching underlying types | |
func emptyOrView<T>(view: T, showView: Bool) -> some MyProtocol where T: MyProtocol { | |
if showView { | |
return someView(view) | |
} else { | |
return emptyView() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is fairly nonsensical and doesn't do anything, but it should compile I think? If
emptyOrView
returns only one ofsomeView(view)
oremptyView()
it works fine. Maybe I need to read more about opaque return types.