Skip to content

Commit 31d13c4

Browse files
committed
Add plugin test to normal CI
The scripted tests only run every night
1 parent f3de3b6 commit 31d13c4

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
183183
}
184184

185185
compileFilesInDir("tests/plugins/neg").checkExpectedErrors()
186+
compileFilesInDir("tests/plugins/pos").checkCompile()
186187
}
187188
}
188189

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package analyzer
2+
3+
import scala.language.implicitConversions
4+
5+
import dotty.tools.dotc._
6+
import core._
7+
import Contexts.Context
8+
import plugins._
9+
import Phases.Phase
10+
import ast.tpd
11+
import transform.MegaPhase.MiniPhase
12+
import Decorators._
13+
import Symbols.Symbol
14+
import Constants.Constant
15+
import Types._
16+
import transform.{SetDefTree, SetDefTreeOff}
17+
18+
class InitChecker extends PluginPhase with StandardPlugin {
19+
import tpd._
20+
21+
val name: String = "initChecker"
22+
override val description: String = "checks that under -Yretain-trees we may get tree for all symbols"
23+
24+
val phaseName = name
25+
26+
override val runsAfter = Set(SetDefTree.name)
27+
override val runsBefore = Set(SetDefTreeOff.name)
28+
29+
def init(options: List[String]): List[PluginPhase] = this :: Nil
30+
31+
private def checkDef(tree: Tree)(implicit ctx: Context): Tree = {
32+
if (tree.symbol.defTree.isEmpty)
33+
ctx.error("cannot get tree for " + tree.show, tree.sourcePos)
34+
tree
35+
}
36+
37+
private def checkable(sym: Symbol)(implicit ctx: Context): Boolean =
38+
sym.exists && !sym.isOneOf(Flags.Package) && !sym.isOneOf(Flags.Param) &&
39+
(sym.isClass || !sym.isOneOf(Flags.Case, butNot = Flags.Enum)) // pattern-bound symbols
40+
41+
private def checkRef(tree: Tree)(implicit ctx: Context): Tree =
42+
if (!checkable(tree.symbol)) tree
43+
else {
44+
val helloPkgSym = ctx.requiredPackage("hello").moduleClass
45+
val libPkgSym = ctx.requiredPackage("lib").moduleClass
46+
val enclosingPkg = tree.symbol.enclosingPackageClass
47+
48+
if (enclosingPkg == helloPkgSym) { // source code
49+
checkDef(tree)
50+
ctx.warning("tree: " + tree.symbol.defTree.show)
51+
}
52+
else if (enclosingPkg == libPkgSym) { // tasty from library
53+
checkDef(tree)
54+
// check that all sub-definitions have trees set properly
55+
// make sure that are no cycles in the code
56+
transformAllDeep(tree.symbol.defTree)
57+
ctx.warning("tree: " + tree.symbol.defTree.show)
58+
}
59+
else {
60+
ctx.warning(tree.symbol + " is neither in lib nor hello, owner = " + enclosingPkg, tree.sourcePos)
61+
}
62+
tree
63+
}
64+
65+
override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = checkDef(tree)
66+
67+
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = checkDef(tree)
68+
69+
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context): Tree = checkDef(tree)
70+
71+
override def transformSelect(tree: Select)(implicit ctx: Context): Tree = checkRef(tree)
72+
73+
override def transformIdent(tree: Ident)(implicit ctx: Context): Tree = checkRef(tree)
74+
75+
override def transformTypeTree(tree: TypeTree)(implicit ctx: Context): Tree = {
76+
tree.tpe.foreachPart {
77+
case tp: NamedType => checkRef(TypeTree(tp))
78+
case _ =>
79+
}
80+
tree
81+
}
82+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package hello
2+
3+
import lib._
4+
5+
case class Student(name: String)
6+
7+
class M(val n: Int) {
8+
val a = 30 * n
9+
def this(c: Char) = this(c.toInt)
10+
11+
class B(x: Int) {
12+
def this(c: Char) = this(c.toInt)
13+
val b = x * a
14+
def bar(i: Int) = i * x
15+
}
16+
17+
def foo(i: Int) = i * n
18+
19+
def bar = {
20+
class C(val s: String)
21+
val c = new C("hello")
22+
def qux = c.s
23+
qux
24+
}
25+
}
26+
27+
28+
object Test {
29+
def testLib: Unit = {
30+
val a: A = new A(30)
31+
val b: a.B = new a.B(24)
32+
a.foo(3)
33+
b.bar(9)
34+
}
35+
36+
def testHello: Unit = {
37+
val a: M = new M(30)
38+
val b: a.B = new a.B(24)
39+
a.foo(3)
40+
b.bar(9)
41+
}
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package lib
2+
3+
class A(val n: Int) {
4+
def this(c: Char) = this(c.toInt)
5+
6+
val a = 30 * n
7+
// val p = Product("x", 100)
8+
9+
class B(x: Int) {
10+
def this(c: Char) = this(c.toInt)
11+
val b = x * a
12+
def bar(i: Int) = i * x
13+
}
14+
15+
def foo(i: Int) = i * n
16+
}
17+
18+
case class Product(name: String, price: Int)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pluginClass=analyzer.InitChecker

0 commit comments

Comments
 (0)