Skip to content

Improve diagnostics when trying to extend existential type #60680

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

Conversation

cbjeukendrup
Copy link
Contributor

Resolves: #60595

@cbjeukendrup cbjeukendrup force-pushed the diag_unsupported_existential_extension branch from 4e445a8 to e35f8d1 Compare August 21, 2022 12:03
@cbjeukendrup cbjeukendrup force-pushed the diag_unsupported_existential_extension branch 2 times, most recently from 0ca8393 to c7d4878 Compare August 23, 2022 00:35
@@ -3042,21 +3042,31 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
const bool wasAlreadyInvalid = ED->isInvalid();
ED->setInvalid();
if (!extType->hasError() && extType->getAnyNominal()) {
auto canExtType = extType->getCanonicalType();
if (auto existential = canExtType->getAs<ExistentialType>()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call getAs() on a non-canonical type, it will automatically desugar it, so you don’t need to move the canonical type computation from below

Copy link
Contributor Author

@cbjeukendrup cbjeukendrup Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using auto existential = extType->getAs<ExistentialType>() instead still gives a difference. The comment for the fixit in the test case becomes "did you mean to extend 'A4' (aka 'P4') instead?", while it will still replace the type with just P4. Wouldn't it be better if the comment just says "did you mean to extend 'P4' instead?"?

Or do we want that the fixit replaces the type with A4 in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think it's better for the error message to mention 'A4' (aka 'P4') because A4 is what's written in the extension, so it helps the programmer make the connection between A4 and P4. However, I don't feel too strongly about this and I'm fine with merging this change as-is.

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@cbjeukendrup
Copy link
Contributor Author

@slavapestov I'm sorry, it turns out I hadn't pushed my latest changes yet, awaiting your opinion on #60680 (comment). I'll push them in a few minutes, after running the tests locally once more!

@cbjeukendrup cbjeukendrup force-pushed the diag_unsupported_existential_extension branch from c7d4878 to d47bba6 Compare September 23, 2022 18:51
@LucianoPAlmeida
Copy link
Contributor

@swift-ci Please test

@LucianoPAlmeida
Copy link
Contributor

cc @slavapestov @hborla

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

Apologies for taking so long to review this. Please feel free to ping me directly if that happens again.

@hborla
Copy link
Member

hborla commented Jan 3, 2023

@swift-ci please smoke test

@hborla
Copy link
Member

hborla commented Jan 5, 2023

@swift-ci please smoke test macOS

@LucianoPAlmeida
Copy link
Contributor

Since we got approval ⛵
Thanks @hborla!

@LucianoPAlmeida LucianoPAlmeida merged commit e5e9827 into swiftlang:main Jan 5, 2023
@cbjeukendrup cbjeukendrup deleted the diag_unsupported_existential_extension branch January 5, 2023 14:03
@hborla
Copy link
Member

hborla commented Jan 5, 2023

Thank you for the contribution @cbjeukendrup!

@cbjeukendrup
Copy link
Contributor Author

Thank you for the contribution @cbjeukendrup!

@hborla Thanks for the review!

By the way, I also have another open PR, namely #58545. Would be great if you could have a look at that one too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect diagnostic when attempting to extend any P
5 participants