blob: 2a318752f11a6ce4db43ea396b007a64b9c9059f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe._
import scala.tools.reflect.ToolBox
object Test {
def test(code: String, log: Boolean = false) {
val tb = currentMirror.mkToolBox()
val tree = tb.parse(code)
val typed = tb.typecheck(tree)
if (log) {
println("=" * 80)
println(typed)
}
val untyped = tb.untypecheck(typed)
if (log) println(untyped)
val retyped = tb.typecheck(untyped)
if (log) println(retyped)
}
def main(args: Array[String]): Unit = {
test("{ class a { val x = 42 }; new a }") // failed
test("{ trait a { val x = 42 }; new a {} }") // worked
test("{ abstract class a { val x: Int } }") // worked
test("{ abstract class a { val x: Int }; new a { val x = 42 } }") // failed
test("{ class a { private val x = 42 }; new a }") // failed
test("{ class a { protected val x = 42 }; new a { x } }") // failed
test("{ class a { protected[a] val x = 42 }; new a }") // failed
}
}
|