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-6315] Error: Cannot convert value of type to expected argument type for Self Reference Protocol #48865

Open
swift-ci opened this issue Nov 7, 2017 · 3 comments
Assignees
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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2017

Previous ID SR-6315
Radar None
Original Reporter davideme (JIRA User)
Type Bug
Status Reopened
Resolution

Attachment: Download

Environment

Version 9.1 (9B55)

Toolchain: Swift 4.1 Snapshot 2017-11-05 (a)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @xedin
Priority Medium

md5: 861161fd3c5321d8b1876268e8c52866

Issue Description:

With the version 4.1 of the compiler, I implemented protocols that use self reference associated type.

I got the following errors:

Cannot convert value of type '(Nuke) -> AttackMonad' to expected argument type '(Nuke) -> _'
Cannot convert value of type '(Target) -> (Nuke, Target)' to expected argument type '(Target) -> _'

Were the compiler is not able to match the types of parameters of 2 methods declared in a protocol.

You can find the code in the following repo:

https://github.com/davideme/Functional-Swift-Error-Handling

In particular the 2 following lines:

@belkadan
Copy link
Contributor

belkadan commented Nov 7, 2017

This seems like correct behavior to me. You don't know from the constraints you have that NukeMonad's associated type F is an AttackMonad. I think you should be making the generic parameter of map and flatMap be the monad rather than the monad's element—if it's appropriate to use those names for something that changes from one monad to another in the first place.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 7, 2017

Comment by Davide Mendolia (JIRA)

@belkadan the compiler is capable to autocomplete and identify the it's expecting a Monad as return value. And AttackMonad is defined as an implementation of Monad.

Now, if this shouldn't be possible in Swift, at least the following error messages should be fixed.

About the semantic of this example, we could rename Monad to Container, it's not really the goal of implementing a Monad to play around with what composition allow in swift.

@belkadan
Copy link
Contributor

belkadan commented Nov 7, 2017

The code completion should probably say NukeMonad.F but I'm not sure if it has that much information. The error message part is sensible, though.

cc @xedin

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants