-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancesgenericsFeature: generic declarations and typesFeature: generic declarations and typesnot a bugResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer erroropaque result typesFeature → types → opaque types: opaque result typesFeature → types → opaque types: opaque result typesopaque typesFeature → types: opaque typesFeature → types: opaque typesswift 5.10type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error
Description
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
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancesgenericsFeature: generic declarations and typesFeature: generic declarations and typesnot a bugResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer erroropaque result typesFeature → types → opaque types: opaque result typesFeature → types → opaque types: opaque result typesopaque typesFeature → types: opaque typesFeature → types: opaque typesswift 5.10type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error