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

Can't inherit from a protocol with primary associated types using the "generic" notation #62906

Open
tgrapperon opened this issue Jan 7, 2023 · 3 comments
Assignees
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 parameterized protocols Feature → protocol: protocols with primary associated types swift 5.9 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@tgrapperon
Copy link

It doesn't seem possible for a struct to inherit a protocol with primary associated type using this primary associated type in the declaration. In other words, the following doesn't compile:

protocol P<A> {
  associatedtype A
}
struct B {}

struct T: P<B> {} // Error: Cannot inherit from protocol type with generic argument 'P<B>'

This configuration was however explicitly mentioned in SE-0346, so I don't know if this is a bug, a regression, or feature that was not implemented at the end.

Environment

  • Swift compiler version info: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
  • Xcode version info: Version 14.2 (14C18)
  • Deployment target: macOS 13.1
@tgrapperon tgrapperon added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 7, 2023
@AnthonyLatsis AnthonyLatsis added parameterized protocols Feature → protocol: protocols with primary associated types compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis and removed triage needed This issue needs more specific labels labels Jan 8, 2023
@AnthonyLatsis
Copy link
Collaborator

It must be that it isn’t implemented yet.

cc @slavapestov

@AnthonyLatsis AnthonyLatsis added the conformances Feature → protocol: protocol conformances label Jan 8, 2023
@joshavant
Copy link

joshavant commented Feb 23, 2023

This works:

protocol P<A> {
  associatedtype A
}
struct B {}

struct T: P {
    typealias A = B
}

@DevAndArtist
Copy link
Contributor

I think this should also be accepted when this issue is fixed:

protocol P<T> {
  associatedtype T
}

struct S {}

class C: P<S> {
  typealias T = S
}

@slavapestov slavapestov self-assigned this Mar 7, 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 parameterized protocols Feature → protocol: protocols with primary associated types swift 5.9 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

5 participants