Skip to content

Commit b09e900

Browse files
committed
Ignore Quote/Slice in init checker
We should never be able to encounter them in usage of macros --- because macros will expand to normal trees without quote and splices. The particular test case is actually problematic: The macro did not expand in `base_0.scala`.
1 parent 5454110 commit b09e900

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1383,11 +1383,11 @@ object Semantic:
13831383
case tpl: Template =>
13841384
init(tpl, thisV, klass)
13851385

1386-
case _: Import | _: Export =>
1386+
case _: Import | _: Export | _: Quote | _: Splice | _: QuotePattern | _: SplicePattern =>
13871387
Hot
13881388

13891389
case _ =>
1390-
report.warning("[Internal error] unexpected tree" + Trace.show, expr)
1390+
report.warning("[Internal error] unexpected tree: " + expr.getClass + ", trace:\n" + Trace.show, expr)
13911391
Hot
13921392

13931393
/** Handle semantics of leaf nodes

tests/init/pos/i18407/base_0.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// base_0.scala
2+
trait BaseTest extends AnyFreeSpecLike {
3+
"empty-test" - {} // ok if we comment out this line
4+
}

tests/init/pos/i18407/macros_0.scala

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// macros_0.scala
2+
object source {
3+
import scala.quoted._
4+
5+
class Position()
6+
7+
object Position {
8+
def withPosition[T](
9+
fun: Expr[Position => T]
10+
)(using quotes: Quotes, typeOfT: Type[T]): Expr[T] = {
11+
'{
12+
${ fun }.apply(new source.Position())
13+
}
14+
}
15+
}
16+
}
17+
18+
trait AnyFreeSpecLike {
19+
import scala.language.implicitConversions
20+
21+
protected final class FreeSpecStringWrapper(
22+
string: String,
23+
pos: source.Position
24+
) {
25+
def -(fun: => Unit): Unit = fun
26+
}
27+
28+
inline implicit def convertToFreeSpecStringWrapper(
29+
s: String
30+
): FreeSpecStringWrapper = {
31+
${
32+
source.Position.withPosition[FreeSpecStringWrapper]('{
33+
(pos: source.Position) => new FreeSpecStringWrapper(s, pos)
34+
})
35+
}
36+
}
37+
}

tests/init/pos/i18407/test_1.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class MyTest extends BaseTest {
2+
"empty-test" - {}
3+
private val myObject = new {}
4+
}

0 commit comments

Comments
 (0)