Skip to content
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

Implement the Any2StringAdd rewrite #10

Merged
merged 4 commits into from
Jun 18, 2019

Conversation

dwijnand
Copy link
Collaborator

@dwijnand dwijnand commented Jun 7, 2019

@dwijnand dwijnand requested a review from lrytz June 7, 2019 05:37
Copy link
Contributor

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

Looks good already! Interesting that it works for bool + s but not byte + s...

rewrites/src/main/scala/fix/scala213/Any2StringAdd.scala Outdated Show resolved Hide resolved
@dwijnand dwijnand changed the title Implement (the start of) the Any2StringAdd rewrite Implement the Any2StringAdd rewrite Jun 7, 2019

private def addToString(term: Term) = term match {
case _: Term.Name | _: Term.Select | _: Term.Block => Patch.addRight(term, ".toString")
case _ => Patch.addLeft(term, "(") + Patch.addRight(term, ").toString")
Copy link
Contributor

Choose a reason for hiding this comment

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

my only concern here is that it unnecessarily boxes primitives.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that must be why the deprecation message for these is to use string interpolation.

Should we do "" + x for these? (And "" + (...) for non-Name/Select/Block.) . Or should we try to rewrite it to use string interpolation?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know. IIRC, string interpolation is special-cased by the compiler in 2.13, so it's probably at least as efficient as other options, if not more so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it's the right choice. But for mechanical rewrites you could get some weird rewrites, so maybe this is best?

Copy link
Contributor

Choose a reason for hiding this comment

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

that must be why the deprecation message for these is to use string interpolation.

IIRC, string interpolation is special-cased by the compiler in 2.13

Yes. see scala/scala#7201 scala/bug#11025

@dwijnand dwijnand requested a review from lrytz June 8, 2019 13:34
Copy link
Contributor

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

nice 👍

@dwijnand dwijnand merged commit 57f1e61 into lightbend-labs:master Jun 18, 2019
@dwijnand dwijnand deleted the any2StringAdd branch June 18, 2019 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants