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

f interpolator render constant string #8608

Closed
scabug opened this issue May 20, 2014 · 5 comments
Closed

f interpolator render constant string #8608

scabug opened this issue May 20, 2014 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 20, 2014

It would be nice if

f"hello, world"  // scala.this.Predef.augmentString("hi").format()

produced just a constant string.

That enables

f"$$ordinary"  // no cost
"$ordinary"     // looks like missing interpolator
f"$$ordinary%n"  // requires format, though could be improved

Locale is never used in rendering FixedString text.

But f just emits "hi".format() and the enhancement could be diverted:

package goodbye

import Predef.{ augmentString => _ }

object Test extends App {

  implicit class `bold format`(s: String) {
    def format(args: Any*): String = {
      Predef require args.isEmpty
      "goodbye, everybody"
    }
  }

  Console println f"hello, world"
}

It's not obvious that this is sipped behavior. Someone wanting a special format could subvert the interpolator directly.

@scabug
Copy link
Author

scabug commented May 20, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8608?orig=1
Reporter: @som-snytt
Affected Versions: 2.11.0

@scabug
Copy link
Author

scabug commented May 20, 2014

@retronym said:
I agree that we should emit java.lang.String.format(....) rather than emitting an untyped "".format(...) and hoping for the best.

@scabug
Copy link
Author

scabug commented May 20, 2014

@som-snytt said:
scala/scala#3769

@scabug
Copy link
Author

scabug commented May 20, 2014

@som-snytt said (edited on May 20, 2014 7:55:31 PM UTC):
It will have to do some extra work since support for

f"${BigDecimal(3.4)}%e"

is in the wrapper, which unwraps.

@scabug
Copy link
Author

scabug commented Jul 15, 2014

@som-snytt said:
scala/scala#3878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants