Scala Programming Language
  1. Scala Programming Language
  2. SI-7325

f string interpolator no longer accepts literal %

    Details

      Description

      scala> f"${0}%.2f%"
      java.util.UnknownFormatConversionException: Conversion = '%'
      

        Activity

        Hide
        Eugene Burmako added a comment - - edited
        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?

        Show
        Eugene Burmako added a comment - - edited 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?
        Hide
        Jason Zaugg added a comment -

        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.

        Show
        Jason Zaugg added a comment - 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 .
        Show
        Eugene Burmako added a comment - http://groups.google.com/group/scala-language/t/9602fdb27c14c56
        Hide
        Paul Phillips added a comment - - edited

        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)
        
        Show
        Paul Phillips added a comment - - edited 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)
        Hide
        A. P. Marki added a comment -

        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.

        Show
        A. P. Marki added a comment - 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.
        Hide
        Eugene Burmako added a comment -

        Note to self: also update the docs.

        Show
        Eugene Burmako added a comment - Note to self: also update the docs.
        Show
        Eugene Burmako added a comment - https://github.com/scala/scala/pull/2461
        Show
        Eugene Burmako added a comment - https://github.com/scalamacros/kepler/commit/cb1a427d8ad4a92690610bfa7d6c79f48d440864

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Jason Zaugg
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development