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-10577] Compiler fails to produce diagnostic for expression when casting protocol to subprotocol #52977

Open
igorcferreira opened this issue Apr 29, 2019 · 3 comments
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 failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression type checker Area → compiler: Semantic analysis

Comments

@igorcferreira
Copy link

Previous ID SR-10577
Radar None
Original Reporter @igorcferreira
Type Bug

Attachment: Download

Environment

Swift 5.0.1
Xcode Version 10.2.1 (10E1001)
macOS 10.14.4 (18E226)

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

md5: 1face1c5ee79656f800914ebc9379fd2

Issue Description:

Inside a flatMap, after a compactMap, the compiler fails to produce diagnostic for "as?" expression when casting protocol to another protocol.

The error message thrown by the compiler reads as follow:

"error: failed to produce diagnostic for expression; please file a bug report"

I attached, here, a Playground that showcases the error message being displayed. Also, the sample code can be seen bellow.

P.s.: When the return method for the flatMap is specified, the compiler is able to understand and compile properly.

import Foundation

protocol Actor {
    var id: String { get }
}

protocol User: Actor {
    var email: String { get }
}

protocol Group: Actor {
    var name: String { get }
}

protocol Conversation {
    var actor: Actor { get }
}

enum StreamError: Error {
    case outOfBounds
}

struct ConversationStream {
    
    let conversations: [Conversation]
    
    func item(at: Int) throws -> Conversation {
        if at < 0 || at >= conversations.count {
            throw StreamError.outOfBounds
        } else {
            return self.conversations[at]
        }
    }
}

let stream = ConversationStream(conversations: [])
let usersToFetch = [Int]()


//let users: [String] = usersToFetch.compactMap({ (index) in //Uncomment this line to see the desired resul
let users = usersToFetch.compactMap({ (index) in
    guard let conversation = try? stream.item(at: index) else {
        return nil
    }
    let actor = conversation.actor as? User //This line fails with the error: failed to produce diagnostic for expression; please file a bug report
    return actor?.id
})
@belkadan
Copy link
Contributor

@xedin, is this related to the other recent "failure to produce diagnostic", or is it a separate case?

@theblixguy
Copy link
Collaborator

Seems to be fixed on 5.1 :

error: generic parameter 'ElementOfResult' could not be inferred
let users = usersToFetch.compactMap({ (index) in
            ^

@igorcferreira
Copy link
Author

@theblixguy Swift 5.1 is expressing a better error message, but still fails to infer the type of the response

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added diagnostics QoI Bug: Diagnostics Quality of Implementation failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression labels Dec 22, 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 failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants