diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2017-02-16 11:05:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 11:05:48 -0800 |
commit | b990e510510e77e516525d225a81cc3c22c94aec (patch) | |
tree | c96f1c9d3b8b255d880baf1761d220b7c47ec870 /test/files | |
parent | 05d5338ff4ee3ffe5ef1c0e33faa1a29480be2b0 (diff) | |
parent | 944db65d63e12ae4e0135999cdc8b9f2695f4102 (diff) | |
download | scala-b990e510510e77e516525d225a81cc3c22c94aec.tar.gz scala-b990e510510e77e516525d225a81cc3c22c94aec.tar.bz2 scala-b990e510510e77e516525d225a81cc3c22c94aec.zip |
Merge pull request #5542 from retronym/ticket/10066
SI-10066 Fix crash in erroneous code with implicits, dynamic
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/t10066.check | 7 | ||||
-rw-r--r-- | test/files/neg/t10066.scala | 38 | ||||
-rw-r--r-- | test/files/pos/t10066.scala | 38 |
3 files changed, 83 insertions, 0 deletions
diff --git a/test/files/neg/t10066.check b/test/files/neg/t10066.check new file mode 100644 index 0000000000..3555205d83 --- /dev/null +++ b/test/files/neg/t10066.check @@ -0,0 +1,7 @@ +t10066.scala:33: error: could not find implicit value for parameter extractor: dynamicrash.Extractor[String] + println(storage.foo[String]) + ^ +t10066.scala:37: error: could not find implicit value for parameter extractor: dynamicrash.Extractor[A] + println(storage.foo) + ^ +two errors found diff --git a/test/files/neg/t10066.scala b/test/files/neg/t10066.scala new file mode 100644 index 0000000000..ef52f333dd --- /dev/null +++ b/test/files/neg/t10066.scala @@ -0,0 +1,38 @@ +package dynamicrash + +import scala.language.dynamics + +class Config + +trait Extractor[A] { + def extract(config: Config, name: String): A +} + +object Extractor { + // note missing "implicit" + val stringExtractor = new Extractor[String] { + override def extract(config: Config, name: String): String = ??? + } +} + +class Workspace extends Dynamic { + val config: Config = new Config + + def selectDynamic[A](name: String)(implicit extractor: Extractor[A]): A = + extractor.extract(config, name) +} + +object Main { + val storage = new Workspace + + // this line works fine + // val a = storage.foo + + // this line crashes the compiler ("head of empty list") + // in ContextErrors$InferencerContextErrors$InferErrorGen$.NotWithinBoundsErrorMessage + println(storage.foo[String]) + + // this line crashes the compiler in different way ("unknown type") + // in the backend, warning: an unexpected type representation reached the compiler backend while compiling Test.scala: <error> + println(storage.foo) +} diff --git a/test/files/pos/t10066.scala b/test/files/pos/t10066.scala new file mode 100644 index 0000000000..bef85cb08c --- /dev/null +++ b/test/files/pos/t10066.scala @@ -0,0 +1,38 @@ +package dynamicrash + +import scala.language.dynamics + +class Config + +trait Extractor[A] { + def extract(config: Config, name: String): A +} + +object Extractor { + // this has "implicit", unlike the corresponding neg test + implicit val stringExtractor = new Extractor[String] { + override def extract(config: Config, name: String): String = ??? + } +} + +class Workspace extends Dynamic { + val config: Config = new Config + + def selectDynamic[A](name: String)(implicit extractor: Extractor[A]): A = + extractor.extract(config, name) +} + +object Main { + val storage = new Workspace + + // this line works fine + // val a = storage.foo + + // this line crashes the compiler ("head of empty list") + // in ContextErrors$InferencerContextErrors$InferErrorGen$.NotWithinBoundsErrorMessage + println(storage.foo[String]) + + // this line crashes the compiler in different way ("unknown type") + // in the backend, warning: an unexpected type representation reached the compiler backend while compiling Test.scala: <error> + println(storage.foo) +} |