Skip to content

Commit b6a54a8

Browse files
committed
SI-8420 don't crash on unquoting of non-liftable native type
Previously quasiquote's type-based dispatch failed to handle situation where unquotee's type is native but non-liftable and was used to splice with non-zero cardinality.
1 parent 79f7e05 commit b6a54a8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/compiler/scala/tools/reflect/quasiquotes/Holes.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ trait Holes { self: Quasiquotes =>
7878
val (strippedTpe, tpe): (Type, Type) = {
7979
val (strippedRank, strippedTpe) = stripIterable(unquotee.tpe, limit = Some(annotatedRank))
8080
if (isBottomType(strippedTpe)) cantSplice()
81-
else if (isNativeType(strippedTpe)) (strippedTpe, iterableTypeFromRank(annotatedRank, strippedTpe))
82-
else if (isLiftableType(strippedTpe)) (strippedTpe, iterableTypeFromRank(annotatedRank, treeType))
81+
else if (isNativeType(strippedTpe)) {
82+
if (strippedRank != NoDot && !(strippedTpe <:< treeType) && !isLiftableType(strippedTpe)) cantSplice()
83+
else (strippedTpe, iterableTypeFromRank(annotatedRank, strippedTpe))
84+
} else if (isLiftableType(strippedTpe)) (strippedTpe, iterableTypeFromRank(annotatedRank, treeType))
8385
else cantSplice()
8486
}
8587

test/files/scalacheck/quasiquotes/ErrorProps.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,27 @@ object ErrorProps extends QuasiquoteProperties("errors") {
172172
tq"_"
173173
""")
174174

175+
property("SI-8420: don't crash on splicing of non-unliftable native type (1)") = fails(
176+
"Can't unquote List[reflect.runtime.universe.Symbol] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.Symbol]",
177+
"""
178+
val l: List[Symbol] = Nil
179+
q"f(..$l)"
180+
""")
181+
182+
property("SI-8420: don't crash on splicing of non-unliftable native type (2)") = fails(
183+
"Can't unquote List[reflect.runtime.universe.FlagSet] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.FlagSet]",
184+
"""
185+
val l: List[FlagSet] = Nil
186+
q"f(..$l)"
187+
""")
188+
189+
property("SI-8420: don't crash on splicing of non-unliftable native type (3)") = fails(
190+
"Can't unquote List[reflect.runtime.universe.Modifiers] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.Modifiers]",
191+
"""
192+
val l: List[Modifiers] = Nil
193+
q"f(..$l)"
194+
""")
195+
175196
// // Make sure a nice error is reported in this case
176197
// { import Flag._; val mods = NoMods; q"lazy $mods val x: Int" }
177198
}

0 commit comments

Comments
 (0)