-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Offer fix-it to re-write ".at(42)" as "[42]". #63673
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
[cxx-interop] Offer fix-it to re-write ".at(42)" as "[42]". #63673
Conversation
Tests incoming.. |
@swift-ci Please Build Toolchain macOS Platform |
lib/Sema/CSDiagnostics.cpp
Outdated
}; | ||
|
||
// Rewrite a call to .at(42) as a subscript. | ||
if (name.getBaseIdentifier().str() == "at" && |
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 think you can use .is("at")
instead here.
"projection of type '%1' not imported", | ||
"projection of type '%1' not imported. " | ||
"Do you want to replace it with a call " | ||
"to the subscript operator?", | ||
(StringRef, StringRef)) |
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.
We usually use DescriptiveDeclKind, Identifier
in cases like this instead of spelling out method
and quotes.
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 think it's important that we explicitly say that this is a C++ method, so I'm not sure DescriptiveDeclKind
will work.
lib/Sema/CSDiagnostics.cpp
Outdated
@@ -3860,7 +3896,9 @@ bool MissingMemberFailure::diagnoseAsError() { | |||
if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) { | |||
ctx.getClangModuleLoader()->diagnoseMemberValue(getName().getFullName(), | |||
baseType); | |||
diagnoseUnsafeCxxMethod(getLoc(), baseType, getName().getFullName()); | |||
getSourceRange().dump(ctx.SourceMgr); |
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.
Nit: I think you forgot to remove dump
@@ -1255,7 +1255,10 @@ class MissingMemberFailure : public InvalidMemberRefFailure { | |||
/// overload to be present, but a class marked as `@dynamicCallable` | |||
/// defines only `dynamicallyCall(withArguments:)` variant. | |||
bool diagnoseForDynamicCallable() const; | |||
|
|||
|
|||
void diagnoseUnsafeCxxMethod(SourceLoc loc, ASTNode anchor, Type baseType, |
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.
Could you please add a small comment there describing what this method is trying to do?
Thanks for the review comments, @xedin! Updated :) |
@swift-ci please test |
@swift-ci Please Build Toolchain macOS Platform |
Only applies to random access collections. The first of many fix-its like this :)
b0b9008
to
c0416b1
Compare
@swift-ci Please Build Toolchain macOS Platform |
@swift-ci please test |
@swift-ci please test |
@swift-ci please test |
@swift-ci please test macOS |
@swift-ci please test macOS |
The fix-its for |
Only applies to random access collections. The first of many fix-its like this :)