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

Swift will not infer opaque return type of generic function #73449

Open
yosshi4486 opened this issue May 6, 2024 · 0 comments
Open

Swift will not infer opaque return type of generic function #73449

yosshi4486 opened this issue May 6, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@yosshi4486
Copy link

yosshi4486 commented May 6, 2024

Description

No response

Reproduction

NG Pattern

When using an opaque type as the return-value, the compiler says "Type 'Impl' does not conform to protocol 'X'".

import SwiftUI

protocol X {
    associatedtype Body: View
    func doSomething<T>(parameter: T) -> Body
}

struct Impl: X {
    // Type 'Impl' does not conform to protocol 'X'
    func doSomething<T>(parameter: T) -> some View {
        Text("Problem Occur")
    }
}

OK Pattern

When using a concrete type as the return-value, the compiler is silent.

import SwiftUI

protocol X {
    associatedtype Body: View
    func doSomething<T>(parameter: T) -> Body
}

struct Impl: X {
    func doSomething<T>(parameter: T) -> Text {
        Text("Problem Occur")
    }
}

Expected behavior

Impl conform X even when it returns some View, and the compiler says nothing.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

Xcode 15.3 (15E204a)
macOS 14.4.1(23E224)

swift-forum discussion: https://forums.swift.org/t/swift-will-not-infer-opaque-return-type-of-generic-function/67233

@yosshi4486 yosshi4486 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 6, 2024
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant