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

Bad diagnostic when inheriting from class in extension #64903

Open
AnthonyLatsis opened this issue Apr 4, 2023 · 13 comments
Open

Bad diagnostic when inheriting from class in extension #64903

AnthonyLatsis opened this issue Apr 4, 2023 · 13 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation extension Feature → declarations: `extension` declarations good first issue Good for newcomers inheritance Feature → type declarations → class: Subclassing and inheritance of class members swift 6.0 type checker Area → compiler: Semantic analysis

Comments

@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Apr 4, 2023

The following errors are misleading and could use a rewording as clear language rules, depending on the kinds of extended and inherited types.

protocol P {}
struct S {}
class C1 {}
class C2 {}

extension C2: S {} // error: inheritance from non-protocol type 'S'
extension C2: C1 {} // error: inheritance from non-protocol type 'C1'
extension C2: C1 & P {} // error: inheritance from class-constrained protocol composition type 'C1 & P'

Environment

  • Swift version 5.9-dev (LLVM 6a04c4848990c70, Swift c1d5118)

NB: How to improve on these is left as an exercise to whoever takes the issue.

@AnthonyLatsis AnthonyLatsis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers diagnostics QoI Bug: Diagnostics Quality of Implementation inheritance Feature → type declarations → class: Subclassing and inheritance of class members swift 5.9 extension Feature → declarations: `extension` declarations labels Apr 4, 2023
@StevenWong12
Copy link
Contributor

Hey all, I'd like to give a try on solving this issue.😀

@Nallu-Swami
Copy link

Hello, can I work on this issue if no progress has been made yet for this issue?

@AnthonyLatsis
Copy link
Collaborator Author

@StevenWong12 Are you working on this?

@StevenWong12
Copy link
Contributor

@Aringopalan Please feel free to take it😊

@Nallu-Swami
Copy link

Thanks a lot @AnthonyLatsis sir

@Nallu-Swami Nallu-Swami removed their assignment Apr 20, 2023
@Nallu-Swami
Copy link

im really sorry i did that by mistake could you pls assign it back to me 😅

@Nallu-Swami
Copy link

The following errors are misleading and could use a rewording as clear language rules, depending on the kinds of extended and inherited types.

protocol P {}
struct S {}
class C1 {}
class C2 {}

extension C2: S {} // error: inheritance from non-protocol type 'S'
extension C2: C1 {} // error: inheritance from non-protocol type 'C1'
extension C2: C1 & P {} // error: inheritance from class-constrained protocol composition type 'C1 & P'

Environment

  • Swift version 5.9-dev (LLVM 6a04c4848990c70, Swift f2bac1a22939a4d)

NB: How to improve on these is left as an exercise to whoever takes the issue.

Reviewing the code and after several tries i believe this to be one optimal rewording

protocol P {}
protocol S {}
class C1 {}
class C2class {}

extension C2class: S {}
class C2: C1 {} 
extension C2class:P {}

@Nallu-Swami
Copy link

If there is any further issue with the code ill work on it and reword it for better compilation

@StevenWong12
Copy link
Contributor

StevenWong12 commented Apr 20, 2023

I think the original vision of this issue is to rewrite the diagnostic message in the type check stage e.g.
error: class can only inherit from protocol in extension declaration

@Nallu-Swami
Copy link

I think the original vision of this issue is to rewrite the diagnostic message in the type check stage e.g.

error: class can only inherit from protocol in extension declaration

Ohhh 🫠, I did a total 360 here but I guess I can still work on it, rephrase all of them to be more readable.

@dk-talks
Copy link

Hey @Aringopalan , Are you still working on the issue?

@Nallu-Swami
Copy link

@dk-talks feel free to take it , im not working it.

@dk-talks
Copy link

Hey @AnthonyLatsis I have resolved this issues. Please have a look at my Pull Request. #65531

@AnthonyLatsis AnthonyLatsis added swift 6.0 type checker Area → compiler: Semantic analysis and removed swift 5.9 labels Sep 5, 2024
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 itself diagnostics QoI Bug: Diagnostics Quality of Implementation extension Feature → declarations: `extension` declarations good first issue Good for newcomers inheritance Feature → type declarations → class: Subclassing and inheritance of class members swift 6.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants