Decorating existing StringContext interpolators s""" and raw"""

Hi all,

when switching from Scala 2.12 to 2.13, I experience compile problem that seems to be related to
StringContext change in macros between 2.12.10 and 2.13.1
.

TL;DR The StringContext methods s and raw can’t be used as function arguments anymore. At least, I’m not able to type them correctly. Help appreciated!

My use case:

I’m decorating the existing interpolators s""" and raw""". The decorators align cascaded multiline strings. I don’t want to re-implement s""" and raw""" from scratch.

implicit class StringContextExtensions(private val sc: StringContext) extends AnyVal {

  def xs(args: Any*): String = align(sc.s, args)

  def xraw(args: Any*): String = align(sc.raw, args)

  private def align(interpolator: Seq[Any] => String, args: Any*): String = "" // impl omitted here

}

The compile error:

Compiling /Users/daniel/git/vavr-io/vavr-1.0.0/generator/Generator.sc
Generator.sc:4062: type mismatch;
 found   : StringContextExtensions.this.sc.s.type
 required: Seq[Any] => String
    def xs(args: Any*): String = align(sc.s, args)
                                          ^
Generator.sc:4070: too few argument lists for macro invocation
    def xraw(args: Any*): String = align(sc.raw, args)
                                            ^
Compilation Failed

Thanks!

1 Like