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-10991] Function Builders & Opaque return types error Xcode 11 / Swift 5.1 #53381

Closed
swift-ci opened this issue Jun 21, 2019 · 6 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself opaque types Feature → types: opaque types result builders Feature: Result builders

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10991
Radar rdar://problem/51594359
Original Reporter MrLotU (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11 Beta 2
Swift 5.1
MacOS 10.14.5

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

md5: c521fc74c5b138b728eac2b09634623a

relates to:

  • SR-55 non-@objc protocol existentials do not conform to their own protocol type

Issue Description:

When using a function builder in combination with an opaque return type, I get the following error:

Cannot convert return expression of type 'Commands' to return type 'some Commands'

From what I read of this error, `Commands` should definitely be convertible to `some Commands`, but to be sure I also tested with a scenario where my functionBuilder instead of `Commands` would return a type conforming to `Commands` resulting in the same error.

You can find the sourcecode (GH gist) here: https://gist.github.com/MrLotU/a3ec8857871ee516a5bd36227976c7e7

@belkadan
Copy link
Contributor

This is actually correct behavior: a protocol value is not the same as a concrete type conforming to that protocol (see SR-55). But the diagnostic could spell that out more clearly. cc @jckarter

@belkadan
Copy link
Contributor

I might also be misreading your code; where is Command defined? (not Commands)

@jckarter
Copy link
Member

This could also be related to a real bug in the function builder implementation, that it doesn't correctly handle the built underlying return type when there is an opaque type. I'd filed that internally as rdar://problem/51594359.

@swift-ci
Copy link
Collaborator Author

Comment by Jari Koopman (JIRA)

@belkadan Thanks for your reply. I know this is the case, however if I (and I added a 2nd file to the gist to reflect this) change the type to something conforming to Commands instead of the protocol type, the same error appears. (See Plugin_v2.swift in the gist). Also, if I remove the some keyword and either set it as just Commands or as the specific type my function builder returns, there are no errors.

As for the Command struct, it's in another file. If you want to take a look at it, you can find it here.

@jckarter From what I've seen in my tests and from what you describe, this might indeed be what's going on. If there is a way to validate this, please let me know. Happy to help 🙂

@gwynne
Copy link
Contributor

gwynne commented Jun 22, 2019

@jckarter Poked at this a bit out of curiosity's sake, it does look like rdar://51594359 to me; the conversion the code requests is not only correct as far as I can tell but actually explicitly specified as valid by SE-0244, per https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md#associated-type-inference specifically. My proof: removing the function builder and instantiating the same types and values directly yields a successful and correct build, ergo the function builder is at fault 🙂.

@DougGregor
Copy link
Member

This looks like it was fixed by #25944

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 opaque types Feature → types: opaque types result builders Feature: Result builders
Projects
None yet
Development

No branches or pull requests

5 participants