Skip to content

[Diagnostics] Improve diagnostics for invalid type access on existential types. #60671

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

Merged
merged 4 commits into from
Aug 22, 2022

Conversation

hborla
Copy link
Member

@hborla hborla commented Aug 20, 2022

This change improves the error message for invalid associated type and type alias access on a protocol or existential type, and fixes a case of missing diagnostics for invalid type access on a generic parameter that is same-type-constrained to an existential type.

Resolves: rdar://88092865

@hborla hborla requested a review from slavapestov August 20, 2022 02:44
@hborla
Copy link
Member Author

hborla commented Aug 22, 2022

@swift-ci please smoke test

@@ -188,6 +187,25 @@ Type TypeResolution::resolveDependentMemberType(

auto *concrete = ref->getBoundDecl();

if (auto concreteBase = genericSig->getConcreteType(baseTy)) {
bool hasUnboundOpener = !!getUnboundTypeOpener();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be !?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, I want the value of getUnboundTypeOpener as a bool. This !! pattern is used elsewhere in TypeCheckType.cpp on getUnboundTypeOpener to do the same thing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh interesting! I didn’t know we had a !!.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't either until I looked at the other call-sites of TypeChecker::isUnsupportedMemberTypeAccess 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn’t know we had a !!

Some time ago this pattern made me hang for a second too. It's just a double negation and equivalent to (bool)getUnboundTypeOpener() in this context.

@hborla
Copy link
Member Author

hborla commented Aug 22, 2022

@swift-ci please smoke test

@hborla hborla merged commit 34d9624 into swiftlang:main Aug 22, 2022
@hborla hborla deleted the invalid-existential-access branch August 22, 2022 23:39
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.

4 participants