Skip to content

[SR-15027] Associated type is not inferred #57355

@jepers

Description

@jepers
Previous ID SR-15027
Radar rdar://problem/81587765
Original Reporter @jepers
Type Bug
Environment

Xcode 12.5.1, macOS 11.4

Xcode 13 beta3, macOS 11.5

Additional Detail from JIRA
Votes 1
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 695475a3af144ed4ae3cd8dbf8d77adb

Issue Description:

This compiles:

protocol P {
  associatedtype T
  var a: T { get }
  var b: T { get }
}

struct S: P {
  let a: Int
  let b: T
} 

but this does not (surprisingly):

protocol P {
  associatedtype T
  var a: T { get }
  var b: T { get }
  var c: T { get }
}

struct S: P {
  let a: Int
  let b: T
  let c: T // ERROR: Reference to invalid associated type 'T' of type 'S'
}

Changing property to func produces same behavior.

Another similar example:

protocol P {
  associatedtype T
  func foo(x: T) -> T
}

struct S: P {
  func foo(x: Int) -> T { 123 } // ERROR: Reference to invalid associated type 'T' of type 'S'
}

Originating thread:
https://forums.swift.org/t/associatedtype-not-inferred/50947

Metadata

Metadata

Assignees

No one assigned

    Labels

    associated type inferencebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesswift 6.0type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions