-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Improve diagnostics when trying to extend existential type #60680
Conversation
4e445a8
to
e35f8d1
Compare
0ca8393
to
c7d4878
Compare
@@ -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>()) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@swift-ci Please smoke test |
@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! |
c7d4878
to
d47bba6
Compare
@swift-ci Please test |
There was a problem hiding this 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.
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
Since we got approval ⛵ |
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! |
Resolves: #60595