Skip to content

Commit 023c7bc

Browse files
committed
Added test to TreeChecker that guards against orphan parameters.
Currently, tests fail. The failures I checked are all related to tailcalls. Not sure whether there are others. This is a blocker for serialization. Orphan parameters cannot be serialized. Maybe rethink the position of tailcalls? It looks to me that the repeated trouble it gives us is more than the effort required to put an efficient tailcall recognition after pattern matching in place. But I might be wrong.
1 parent f1aa075 commit 023c7bc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Compiler {
4141
List(new FirstTransform,
4242
new SyntheticMethods),
4343
List(new SuperAccessors),
44-
// pickling goes here
44+
//List(new Pickler), // Pickler needs to come last in a group since it should not pickle trees generated later
4545
List(new RefChecks,
4646
new ElimRepeated,
4747
new ElimLocals,

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,28 @@ class TreeChecker {
139139
assert(isSubType(tree1.tpe, tree.typeOpt), divergenceMsg(tree1.tpe, tree.typeOpt))
140140
tree1
141141
}
142+
checkNoOrphans(res.tpe)
142143
phasesToCheck.foreach(_.checkPostCondition(res))
143144
res
144145
}
146+
147+
/** Check that PolyParams and MethodParams refer to an enclosing type */
148+
def checkNoOrphans(tp: Type)(implicit ctx: Context) = new TypeMap() {
149+
val definedBinders = mutable.Set[Type]()
150+
def apply(tp: Type): Type = {
151+
tp match {
152+
case tp: BindingType =>
153+
definedBinders += tp
154+
mapOver(tp)
155+
definedBinders -= tp
156+
case tp: ParamType =>
157+
assert(definedBinders.contains(tp.binder), s"orphan param: $tp")
158+
case _ =>
159+
mapOver(tp)
160+
}
161+
tp
162+
}
163+
}.apply(tp)
145164

146165
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = {
147166
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)

test/dotc/tests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class tests extends CompilerTest {
1515

1616
implicit val defaultOptions = noCheckOptions ++ List(
1717
"-Yno-deep-subtypes",
18-
"-Ycheck:resolveSuper,mixin,restoreScopes",
18+
"-Ycheck:tailrec,resolveSuper,mixin,restoreScopes",
1919
"-d", "./out/"
2020
)
2121

0 commit comments

Comments
 (0)