Skip to content

[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

Merged
merged 10 commits into from
Feb 22, 2023

Conversation

zoecarver
Copy link
Contributor

Only applies to random access collections. The first of many fix-its like this :)

@zoecarver
Copy link
Contributor Author

Tests incoming..

@zoecarver
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

};

// Rewrite a call to .at(42) as a subscript.
if (name.getBaseIdentifier().str() == "at" &&
Copy link
Contributor

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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);
Copy link
Contributor

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,
Copy link
Contributor

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?

@zoecarver
Copy link
Contributor Author

Thanks for the review comments, @xedin! Updated :)

@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

@zoecarver zoecarver force-pushed the fixits-for-common-swiftifications branch from b0b9008 to c0416b1 Compare February 21, 2023 00:00
@zoecarver
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci please test macOS

@zoecarver
Copy link
Contributor Author

@swift-ci please test macOS

@zoecarver
Copy link
Contributor Author

The fix-its for .end() -> nil are a bit broken. Will fix that after the fact.

@zoecarver zoecarver merged commit 5406f1a into swiftlang:main Feb 22, 2023
@hyp hyp added the c++ interop Feature: Interoperability with C++ label Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants