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-15027] Associated type is not inferred #57355

Closed
jepers opened this issue Aug 5, 2021 · 2 comments · Fixed by #69826
Closed

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

jepers opened this issue Aug 5, 2021 · 2 comments · Fixed by #69826
Labels
associated type inference bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances swift 6.0 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@jepers
Copy link

jepers commented Aug 5, 2021

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

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 13, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 14, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 14, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 14, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
@slavapestov
Copy link
Member

Fixed by #69826

slavapestov added a commit to slavapestov/swift that referenced this issue Nov 17, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances associated type inference unexpected error Bug: Unexpected error swift 6.0 labels Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
associated type inference bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances swift 6.0 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants