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

Standard Interpolator should call process, not treatEscapes

    Details

      Description

      Just looking at the source for StringContext. In the 'while (ai.hasNext)' loop, it calls treatEscapes. I think it should call the 'process' function passed in as a parameter.

        Activity

        Hide
        Josh Suereth added a comment -

        For refrence:

        def standardInterpolator(process: String => String, args: Seq[Any]): String = {
            checkLengths(args)
            val pi = parts.iterator
            val ai = args.iterator
            val bldr = new java.lang.StringBuilder(process(pi.next()))
            while (ai.hasNext) {
              bldr append ai.next
              bldr append treatEscapes(pi.next())
            }
            bldr.toString
          }
        

        This means that the raw interpolator does not work correctly:

          def raw(args: Any*): String = standardInterpolator(identity, args)
        
        Show
        Josh Suereth added a comment - For refrence: def standardInterpolator(process: String => String, args: Seq[Any]): String = { checkLengths(args) val pi = parts.iterator val ai = args.iterator val bldr = new java.lang.StringBuilder(process(pi.next())) while (ai.hasNext) { bldr append ai.next bldr append treatEscapes(pi.next()) } bldr.toString } This means that the raw interpolator does not work correctly: def raw(args: Any*): String = standardInterpolator(identity, args)
        Hide
        Jan Niehusmann added a comment -

        Stumbled across this bug just minutes after starting to play with 2.10.0-RC2:

        scala> val x = "x"
        x: String = x
        
        scala> raw"\n$x\n"
        res1: String = 
        "\nx
        "
        

        It seems like there is a patch already committed (0b7aaa5 by Julien Richard-Foy), which is on the master branch, but not in 2.10.0-RC2.

        Show
        Jan Niehusmann added a comment - Stumbled across this bug just minutes after starting to play with 2.10.0-RC2: scala> val x = "x" x: String = x scala> raw"\n$x\n" res1: String = "\nx " It seems like there is a patch already committed (0b7aaa5 by Julien Richard-Foy), which is on the master branch, but not in 2.10.0-RC2.
        Hide
        Josh Suereth added a comment -

        This was already reported and fixed in 2.10.x branch. Since this was found during the RC cycle, and there is a workaround (defining your own raw interpolator) the fix is delayed until the 2.10.1 release in Feb. Sorry for any inconvenience.

        Show
        Josh Suereth added a comment - This was already reported and fixed in 2.10.x branch. Since this was found during the RC cycle, and there is a workaround (defining your own raw interpolator) the fix is delayed until the 2.10.1 release in Feb. Sorry for any inconvenience.
        Hide
        Rex Kerr added a comment -

        Please change the docs on raw to state that it is broken if it's not going to be fixed for .0. The first thing I did with raw was not raw, which was (1) confusing given that there was no documentation and (2) would not inspire a lot of confidence in me for using a .0 release if I wasn't following the dev process and tried this early.

        Show
        Rex Kerr added a comment - Please change the docs on raw to state that it is broken if it's not going to be fixed for .0. The first thing I did with raw was not raw, which was (1) confusing given that there was no documentation and (2) would not inspire a lot of confidence in me for using a .0 release if I wasn't following the dev process and tried this early.
        Hide
        Jason Zaugg added a comment -

        Josh: I don't see how we can change the semantics in a dot-one release (or any other release, really.) IMO, we should remove it or fix it.

        Show
        Jason Zaugg added a comment - Josh: I don't see how we can change the semantics in a dot-one release (or any other release, really.) IMO, we should remove it or fix it.
        Hide
        Martin Odersky added a comment -

        Jason: We can change the semantics if we clearly state it in the release note or the doc comment. That said I am also OK in fixing it now, if there is to be another RC. Not having an opinion for or against.

        Show
        Martin Odersky added a comment - Jason: We can change the semantics if we clearly state it in the release note or the doc comment. That said I am also OK in fixing it now, if there is to be another RC. Not having an opinion for or against.
        Hide
        Jason Zaugg added a comment -

        Reopening for backport to 2.10.0

        https://github.com/scala/scala/pull/1616

        Show
        Jason Zaugg added a comment - Reopening for backport to 2.10.0 https://github.com/scala/scala/pull/1616

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Curtis Stanford
          • Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development