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-8028] Protocol with where class constraint fails to compile, but same extension succeeds #50561

Closed
iby opened this issue Jun 18, 2018 · 7 comments · Fixed by #71354
Closed
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 Self in protocol Feature → types: The 'Self' type in protocols swift 5.10 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@iby
Copy link

iby commented Jun 18, 2018

Previous ID SR-8028
Radar rdar://problem/42012633
Original Reporter @iby
Type Bug
Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee @slavapestov
Priority Medium

md5: c93b6bd151a70d62522f417b2869296d

cloned to:

  • SR-8247 Associated type inheriting from generic class with Self as a parameter prints canonical type in errors

is duplicated by:

  • SR-9706 Compiler rejecting conformance

Issue Description:

Apologies if the sample a little noisy, tried cleaning it up as much as could in available time. The following fails to build, but replaced with commented lines does compile. Intentional? Why?

@belkadan
Copy link
Contributor

This one seems like it ought to work. @huonw?

@slavapestov
Copy link
Member

Another "protocol where clause has superclass constraint" bug

@slavapestov
Copy link
Member

Actually this bug is different. Reduction:

protocol SecureCodingProvider {
  associatedtype T : Generic<Self>
}

class Generic<Value> {}

internal struct Foo {
}

extension Foo: SecureCodingProvider {
  class T: Generic<Foo> {}
}

@slavapestov
Copy link
Member

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented Jul 13, 2018

master...huonw:subclass-witness has a patch that half solves this (the current code is "obviously" wrong), but doesn't solve the problem completely due to recursion issues like:

protocol SecureCodingProvider {
  associatedtype T : Generic<Self.U>
  associatedtype U
}

class Generic<Value> {}

internal struct Foo: SecureCodingProvider {
  class T: Generic<U> {}
  struct U {}
}

Compiling the above with the patch above crashes, and I don't have time right now to solve it properly.

@slavapestov
Copy link
Member

Another test case to verify once this is fixed:

protocol BaseInterface {
  associatedtype Mode: Equatable
}

protocol P {}
class GenericStorage<Mode: Equatable> {}
typealias SpecialStorage<Mode: Equatable> = GenericStorage<Mode> & P

protocol StorageInterface: BaseInterface {
  associatedtype StorageA: GenericStorage<Mode>
  associatedtype StorageB: SpecialStorage<Mode>
}

enum ConcreteMode: Equatable {}

class A: GenericStorage<ConcreteMode> {}
class B: A, P {}

// rejected
struct ConcreteInterface: StorageInterface {
  typealias Mode = ConcreteMode
  typealias StorageA = A
  typealias StorageB = B
}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@slavapestov
Copy link
Member

Fixed by #71354

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 Self in protocol Feature → types: The 'Self' type in protocols swift 5.10 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