Skip to content

[SR-55] non-@objc protocol existentials do not conform to their own protocol type #42677

@swift-ci

Description

@swift-ci
Previous ID SR-55
Radar rdar://problem/21341337
Original Reporter siarhei.barysenka (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 40
Component/s Compiler
Labels Bug
Assignee @slavapestov
Priority Medium

md5: 4333a622f7ff4546521a5fc9f3702a7d

is duplicated by:

  • SR-1176 Using protocols (inheriting from class) as generic parameter which needs to be of type AnyObject fails
  • SR-1324 Passing a parameter of type protocol P to a generic method with a protocol P constraint fails
  • SR-1581 Can not use protocol to fulfill associatedtype requirement where associatedType has protocol constraint
  • SR-2020 Protocol composition doesn't conform to associated type requirement
  • SR-2580 Call to a generic function that expects argument to conform a protocol fails if argument compose multiple protocols.
  • SR-2704 T: Protocol generic constraint doesn't accept protocol existentials
  • SR-3038 Cannot pass in a protocol type to a constrained generic parameter
  • SR-5188 Class existentials don't conform to protocols that the class conforms to
  • SR-5341 Protocol with associatedtype constrained to another protocol & inheritance does not compile
  • SR-5357 Type-constrained protocol cannot be used as a generic argument for similarly constrained generic parameter
  • SR-5777 Existential Metatype in generics
  • SR-6039 A protocol A: class is not any AnyObject
  • SR-6173 Problems with generics + AnyObject or class protocol conformance
  • SR-6645 EXC_BAD_ACCESS in code using protocol extension for defining default implementation
  • SR-7008 Subclass existential doesn't satisfy generic class constraints
  • SR-7412 Swift crashes when a class conforms to a protocol with associated type as AnyObject
  • SR-7563 Generic class with AnyObject constraint won't except protocol that also has AnyObject constraint
  • SR-8261 Generics don't identify Protocol with class requirement properly
  • SR-8624 Unable to use protocol with class type where AnyObject is expected
  • SR-8637 'Protocol composition type' with generic types/inheritance
  • SR-8893 AnyObject constraint on generic type parameter doesn't work when a protocol type is passed as an argument
  • SR-10031 Constraints involving a Class & Protocol constraint don't type check correctly
  • SR-10053 Protocols extending class types are not recognized as class types

relates to:

  • SR-7332 Conditional conformance over array of heterogenous values that share a protocol conformance fails
  • SR-10991 Function Builders & Opaque return types error Xcode 11 / Swift 5.1
  • SR-10907 Default implementation not picked up when conforming to two protocols at once
  • SR-1581 Can not use protocol to fulfill associatedtype requirement where associatedType has protocol constraint
  • SR-7343 Generic constraint fails to infer type when expecting sub protocol

Issue Description:

Summary:
The compiler throws the error

generic parameter 'T' could not be inferred

at the final line of the following code:

protocol MediaProtocol {}
protocol ImageProtocol: MediaProtocol {}

class Image: ImageProtocol {}

func itemToProcess() -> ImageProtocol {
    return Image()
}

//func process<T>(item: T) -> T { // Uncomment this line and comment out the following one to remove the compile-time error
func process<T: MediaProtocol>(item: T) -> T {
    return item
}

let image = itemToProcess()
let processedImage: ImageProtocol = process(image)

The error is gone when conformance to `MediaProtocol` is removed from the generic type `T` at the `process` method declaration in the given code.

Reproduced on:
Xcode 7.1.1 (7B1005), Swift 2.1, OS X 10.11

Metadata

Metadata

Assignees

Labels

compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesfeatureA feature request or implementationprotocolFeature → type declarations: Protocol declarations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions