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 string interpolator no longer accepts literal % #7325

Closed
scabug opened this issue Apr 3, 2013 · 9 comments
Closed

f string interpolator no longer accepts literal % #7325

scabug opened this issue Apr 3, 2013 · 9 comments

Comments

@scabug
Copy link

scabug commented Apr 3, 2013

scala> f"${0}%.2f%"
java.util.UnknownFormatConversionException: Conversion = '%'
@scabug
Copy link
Author

scabug commented Apr 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7325?orig=1
Reporter: @retronym
Affected Versions: 2.11.0-M2
Other Milestones: 2.11.0-M3

@scabug
Copy link
Author

scabug commented Apr 3, 2013

@xeno-by said (edited on Apr 3, 2013 3:02:56 PM UTC):

scala> "%.2f%".format(0.0)
java.util.UnknownFormatConversionException: Conversion = '%'
	at java.util.Formatter.checkText(Formatter.java:2503)
	at java.util.Formatter.parse(Formatter.java:2485)
	at java.util.Formatter.format(Formatter.java:2414)
	at java.util.Formatter.format(Formatter.java:2367)
	at java.lang.String.format(String.java:2769)

Why should f"" behave differently?

@scabug
Copy link
Author

scabug commented Apr 3, 2013

@retronym said:
At minimum it should be a compile time error, as per the other invalid format errors.

I think it might be worth a trip to scala-language or scala-sips to find a consensus. Personally, I'm not strongly attached to the 2.10.x behaviour. One way or another, we should explicitly tests this, document the decision in the Scaladoc for f, and in http://docs.scala-lang.org/overviews/core/string-interpolation.html.

@scabug
Copy link
Author

scabug commented Apr 4, 2013

@scabug
Copy link
Author

scabug commented Apr 4, 2013

@paulp said (edited on Apr 4, 2013 5:35:05 AM UTC):
Escaping it is also broken:

scala> f"%%"
java.util.UnknownFormatConversionException: Conversion = '%'
	at java.util.Formatter.checkText(Formatter.java:2547)
	at java.util.Formatter.parse(Formatter.java:2533)
	at java.util.Formatter.format(Formatter.java:2469)
	at java.util.Formatter.format(Formatter.java:2423)

@scabug
Copy link
Author

scabug commented Apr 11, 2013

@som-snytt said:
It would be nice if I could do f"$i%n" instead of f"$i%s%n" or f"$i%d%n" or s"$i$EOL".

So long as we're on a trip to sip.

@scabug
Copy link
Author

scabug commented Apr 27, 2013

@xeno-by said:
Note to self: also update the docs.

@scabug
Copy link
Author

scabug commented Apr 27, 2013

@xeno-by said:
scala/scala#2461

@scabug scabug closed this as completed May 11, 2013
@scabug
Copy link
Author

scabug commented May 16, 2013

@xeno-by said:
scalamacros/kepler@cb1a427

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