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-13274] Incorrect diagnostic "inherits from itself" on using CRTP #55714

Open
typesanitizer opened this issue Jul 24, 2020 · 4 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@typesanitizer
Copy link

Previous ID SR-13274
Radar rdar://problem/66034611
Original Reporter @typesanitizer
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: d62c6c6302980168d341cac388f1d0b1

Issue Description:

Consider the code below:

protocol P {
  associatedtype AT: P
}

class B<T : P> : P {
  typealias AT = T.AT
}

class C : B<C> {
  //  ^---|-- error: 'C' inherits from itself
  //      ^----- error: type 'C' does not conform to protocol 'P'
  typealias AT = C
} 

It's not super obvious to me whether this code should compile or not, because this probably requires a complex notion of consistency-checking. But the diagnostic error: 'C' inherits from itself is inaccurate, C is not inheriting from itself.

@typesanitizer
Copy link
Author

cc @AnthonyLatsis – not sure if this is related to your upcoming work in #31092

@typesanitizer
Copy link
Author

@swift-ci create

@typesanitizer
Copy link
Author

(I don't have an actual use case for this, I was trying to test how far I could stretch the recursion, since basic examples seemed to work fine.)

@AnthonyLatsis
Copy link
Collaborator

Yeah, this is a separate issue. We recurse into SuperclassTypeRequest while looking up C: P for B<C>. We need a way to ask for the unspecialized conformance to avoid the circularity.
Reduced case:

protocol P {}


class B<T: P> : P {}


class C: B<C> {}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants