diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-03-25 11:57:01 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-03-25 11:57:01 +0100 |
commit | 430e9d88ed0bc58782638c97733690daa18596f8 (patch) | |
tree | fcf4f94ffe6152356f186f922e7dee2bf7f7ea8b | |
parent | 2aeb90778eafb8c3afdb102989546dbe28a41da4 (diff) | |
parent | b6a54a8fa71515fd97c5f225c11b24d971a703c8 (diff) | |
download | scala-430e9d88ed0bc58782638c97733690daa18596f8.tar.gz scala-430e9d88ed0bc58782638c97733690daa18596f8.tar.bz2 scala-430e9d88ed0bc58782638c97733690daa18596f8.zip |
Merge pull request #3637 from densh/si/8420
SI-8420 don't crash on unquoting of non-liftable native type
-rw-r--r-- | src/compiler/scala/tools/reflect/quasiquotes/Holes.scala | 6 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/ErrorProps.scala | 21 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala b/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala index 8376fca4ad..55a28f9f20 100644 --- a/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala +++ b/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala @@ -78,8 +78,10 @@ trait Holes { self: Quasiquotes => val (strippedTpe, tpe): (Type, Type) = { val (strippedRank, strippedTpe) = stripIterable(unquotee.tpe, limit = Some(annotatedRank)) if (isBottomType(strippedTpe)) cantSplice() - else if (isNativeType(strippedTpe)) (strippedTpe, iterableTypeFromRank(annotatedRank, strippedTpe)) - else if (isLiftableType(strippedTpe)) (strippedTpe, iterableTypeFromRank(annotatedRank, treeType)) + else if (isNativeType(strippedTpe)) { + if (strippedRank != NoDot && !(strippedTpe <:< treeType) && !isLiftableType(strippedTpe)) cantSplice() + else (strippedTpe, iterableTypeFromRank(annotatedRank, strippedTpe)) + } else if (isLiftableType(strippedTpe)) (strippedTpe, iterableTypeFromRank(annotatedRank, treeType)) else cantSplice() } diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/files/scalacheck/quasiquotes/ErrorProps.scala index 3d9b27de77..9433965935 100644 --- a/test/files/scalacheck/quasiquotes/ErrorProps.scala +++ b/test/files/scalacheck/quasiquotes/ErrorProps.scala @@ -172,6 +172,27 @@ object ErrorProps extends QuasiquoteProperties("errors") { tq"_" """) + property("SI-8420: don't crash on splicing of non-unliftable native type (1)") = fails( + "Can't unquote List[reflect.runtime.universe.Symbol] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.Symbol]", + """ + val l: List[Symbol] = Nil + q"f(..$l)" + """) + + property("SI-8420: don't crash on splicing of non-unliftable native type (2)") = fails( + "Can't unquote List[reflect.runtime.universe.FlagSet] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.FlagSet]", + """ + val l: List[FlagSet] = Nil + q"f(..$l)" + """) + + property("SI-8420: don't crash on splicing of non-unliftable native type (3)") = fails( + "Can't unquote List[reflect.runtime.universe.Modifiers] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.Modifiers]", + """ + val l: List[Modifiers] = Nil + q"f(..$l)" + """) + // // Make sure a nice error is reported in this case // { import Flag._; val mods = NoMods; q"lazy $mods val x: Int" } } |