Skip to content

String interpolation doesn't work well with implicits #6382

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
scabug opened this issue Sep 17, 2012 · 2 comments
Closed

String interpolation doesn't work well with implicits #6382

scabug opened this issue Sep 17, 2012 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 17, 2012

String interpolation when used with implicits throws weird runtime exception.

Example code:

object Test extends App {

  implicit def CustomPattern(ctx: StringContext) = new {
    object pattern {
      def unapplySeq(s: String): Option[Seq[String]] = Some(Seq())
    }
  }

  println("" match { case pattern"" => "yay!" })
} 

Runtime error:

java.lang.IllegalAccessError: tried to access field sandbox.CustomPatternTest$.reflParams$Cache1 from class sandbox.CustomPatternTest$delayedInit$body
	at sandbox.CustomPatternTest$delayedInit$body.<clinit>(Test.scala:11)
	at sandbox.CustomPatternTest$.<init>(Test.scala:3)
	at sandbox.CustomPatternTest$.<clinit>(Test.scala)
	at sandbox.CustomPatternTest.main(Test.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:71)
	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:139)
	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:71)
	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:139)
	at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
	at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@scabug
Copy link
Author

scabug commented Sep 17, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6382?orig=1
Reporter: @densh
Affected Versions: 2.10.0-M7

@scabug
Copy link
Author

scabug commented Sep 17, 2012

@paulp said:
It has nothing to do with string interpolation or implicits; it is a bug in delayedinit, and a duplicate of #5565. Use a main method instead of "extends App" and it works.

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