Skip to content

Name translation: Allow type name translation when cursor points to constructor call. rdar://33163114 #10872

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 2 commits into from
Jul 11, 2017
Merged

Conversation

nkcsgexi
Copy link
Contributor

When translating objc names to swift names, if the given name is not an objc
function name, and the cursor points to a constructor call, we use the type
declaration instead of the init declaration to translate.

…onstructor call. rdar://33163114

When translating objc names to swift names, if the given name is not an objc
function name, and the cursor points to a contructor call, we use the type
declaration instead of the init declaration to translate.
@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi requested a review from benlangmuir July 11, 2017 01:09
@nkcsgexi
Copy link
Contributor Author

@benlangmuir does this look safe for swift 4.0?

// FIXME: Should pass the main module for the interface but currently
// it's not necessary.
passNameInfoForDecl(Entity.Dcl, NewInput, Receiver);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why doesn't this break anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for generated interface; we don't run name translation on that.

@@ -66,6 +67,7 @@ class MyDerived: FooClassDerived {
// CHECK9: fooProperty11
// CHECK10: init(nstanceFunc21:)
// CHECK11: init(lassDerived2:)
// CHECK11-1: FooClassDerived2
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the other direction (Swift to Objc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should only happen on Objc->Swift, right? where cursor is selected by indexer at a random place. For the other direction, we actually have the cursor user points to,
so we don’t need this modification.

Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming from the Foo in Foo(x: 1) will currently rename the typename, which tries to name-translate the initializer name, leading to broken code after rename. If possible, it would be best to have this location work for both init and typename in both directions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When renaming from the Foo in Foo(x: 1), we translate the type name instead of initializer name; and that's in consistence with our intended behavior. I cannot think of a situation when we need such lenience when renaming from Swift side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignore my above comments, I think we have the similar situation in Swift as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that something that changed in this commit, because it's not what I see right now. I see it trying to find the initializer name, which then causes us to change Foo to fooWithX in the ObjC code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. We need to add the similar logic to handle swift->objc translation as well.

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi
Copy link
Contributor Author

@benlangmuir mind taking another look?

@benlangmuir
Copy link
Contributor

LGTM, thanks!

@nkcsgexi nkcsgexi merged commit 243ec5a into swiftlang:master Jul 11, 2017
@nkcsgexi nkcsgexi deleted the name-translate-redirect branch July 11, 2017 19:46
nkcsgexi added a commit that referenced this pull request Jul 11, 2017
nkcsgexi added a commit that referenced this pull request Jul 11, 2017
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.

2 participants