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-14604] Confusing constrained error message when extending inherited nested classes #56956

Open
swift-ci opened this issue May 6, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 6, 2021

Previous ID SR-14604
Radar rdar://problem/77673439
Original Reporter uliwitness (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 83bd398f344e0f75125b04073945e344

Issue Description:

I have

final public class A<T> {
    public struct AB {
    }
}
final public class C<T>: A<T> {
}

I'm trying to extend it:

extension C.AB {
}  

But this gives a confusing error

Constrained extension must be declared on the unspecialized generic type 'AB' with constraints specified by a 'where' clause

The trick to making it work is

extension A.AB {
} 

Though theoretically that allows using the extension with A as well, which might be semantically wrong and confusing to users in some situations.

In any event, I mainly think that, if at the compiler level there is no need or no ability to distinguish between A.AB and C.AB (actually "inheriting" a nested type as a distinctly referenceable entity would be the ideal case), at the least I would want it to present a more helpful error message like "No nested type AB in C, did you perhaps mean A.AB from the superclass?".

@typesanitizer
Copy link

@swift-ci create

@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
Projects
None yet
Development

No branches or pull requests

2 participants