-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Improve diagnostics on invalid open extensions #38989
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
[Diagnostics] Improve diagnostics on invalid open extensions #38989
Conversation
6c948b6
to
19a0821
Compare
19a0821
to
55557be
Compare
lib/Sema/TypeCheckAttr.cpp
Outdated
for (auto Member : extension->getMembers()) { | ||
if (auto *VD = dyn_cast<ValueDecl>(Member)) { | ||
if (VD->getAttrs().hasAttribute<AccessControlAttr>()) | ||
return; |
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.
return; | |
continue; |
Also, to catch this, I recommend shuffling the order of members in the test case, so that we make sure we emit fix-its for later members even if we skip it for members in-between.
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.
Seems logical 👍 I fixed the test cases as well :)
31f7707
to
24dbd85
Compare
test/attr/open.swift
Outdated
private var G: Int { 3 } // Okay | ||
} | ||
|
||
import Foundation |
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.
Due to use of this import Foundation
, you should use -sdk %clang-importer-sdk
in the third RUN
line, since we don't need the "real" Foundation
, the fake one in the test suite should be good enough.
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 didn't know that existed, thanks :) Added and pushed!
24dbd85
to
2b2cd54
Compare
@swift-ci smoke test |
It seems like the use of |
Hmm, the test needs |
@@ -1499,7 +1499,7 @@ ERROR(access_control_extension_more,none, | |||
"be declared %select{%error|fileprivate|internal|public|%error}2", | |||
(AccessLevel, DescriptiveDeclKind, AccessLevel)) | |||
ERROR(access_control_extension_open,none, | |||
"extensions cannot use 'open' as their default access; use 'public'", | |||
"extensions cannot be marked 'open'; mark individual members as 'open' instead", |
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.
"Mark" works but I don't know that we use this term very often in Swift diagnostics. How about "declare" as above and 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.
Seems good! Fixed 👍
2b2cd54
to
84c42a8
Compare
@swift-ci smoke test |
84c42a8
to
0b48569
Compare
Can someone run the tests again please? :) |
@swift-ci smoke test |
Using 'open' as default access for an extension results in the following error:
Applying the autocorrect and making the function as open instead, the code is changed to this and warning is emitted:
where the warning holds no purpose because the 'open' modifier still works. (It seems like this is the case for other types of this conflict, i.e. public function in a private extension, and the function is still publicly visible. Similar thing can be observed in classes, i.e. a private class with a public variable, and no warning is shown there)
To remove the warning, you have to now remove the 'public' modifier like this:
I think we can improve these diagnostics to something like this to make this more convenient:
Resolves SR-15071