Skip to content

Parsing error with $_ and $_id in interpolated strings #1779

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

Closed
liufengyun opened this issue Dec 8, 2016 · 1 comment
Closed

Parsing error with $_ and $_id in interpolated strings #1779

liufengyun opened this issue Dec 8, 2016 · 1 comment

Comments

@liufengyun
Copy link
Contributor

Dotty cannot parse $_ and $_id, while Scalac only supports $_.

object Test {
  implicit class Foo(sc: StringContext) {
    object q {
      def unapply(arg: Any): Option[(Any, Any)] =
        Some((sc.parts(0), sc.parts(1)))
    }
  }

  def main(args: Array[String]): Unit = {
    val q"class $_ extends $_parent" = new Object
    println(_parent)
  }
}
@liufengyun
Copy link
Contributor Author

Forward a comment by @xeno-by :

In scalac, this only works for interpolation strings in patterns:

06:29 ~/Projects/2121/sandbox (HEAD)$ parse 'q"foo${_}"'
/var/folders/81/zf4z2j9s4kl7qy76tgnhk2mh0000gn/T/tmp1M2lFu:2: error: unbound placeholder parameter
  q"foo${_}"
         ^

06:29 ~/Projects/2121/sandbox (HEAD)$ parse 'val q"foo${_}" = ???'
[[syntax trees at end of parser]]// Scala source: tmpbmFgw5
package <empty> {
  class wrapper extends scala.AnyRef {
    def <init>() = {
      super.<init>();
      ()
    };
    <synthetic> <artifact> private[this] val x$1 = $qmark$qmark$qmark: @scala.unchecked match {
      case StringContext("foo", "").q(_) => ()
    }
  }
}

odersky added a commit that referenced this issue Dec 15, 2016
fix #1779: support $_ and $_id  in interpolated string
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