diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t7185.check | 4 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TypecheckedProps.scala | 72 |
2 files changed, 74 insertions, 2 deletions
diff --git a/test/files/run/t7185.check b/test/files/run/t7185.check index 2b4adf36b4..ebf85b731f 100644 --- a/test/files/run/t7185.check +++ b/test/files/run/t7185.check @@ -24,7 +24,9 @@ tree: reflect.runtime.universe.Apply = scala> {val tb = reflect.runtime.currentMirror.mkToolBox(); tb.typecheck(tree): Any} res0: Any = { - $read.O.apply() + { + $read.O.apply() + } } scala> diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala index 8b1cb6cc49..432c0959c9 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -65,7 +65,7 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { } property("extract UnApply (2)") = test { - val q"object $_ { $_; $_; $m }" = typecheck(q""" + val q"object $_ { $_; $m }" = typecheck(q""" object Test { case class Cell(val x: Int) new Cell(0) match { case Cell(v) => v } @@ -82,4 +82,74 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { val q"val x: ${tq""} = 42" = typechecked val q"val x: ${t: Type} = 42" = typechecked } + + property("class with param (1)") = test { + val paramName = TermName("x") + val q"class $_($param)" = typecheck(q"class Test(val $paramName: Int)") + + assert(param.name == paramName) + } + + property("class with param (2)") = test { + val paramName = TermName("y") + val q"{class $_($param)}" = typecheck(q"class Test(val $paramName: Int = 3)") + + assert(param.name == paramName) + assert(param.rhs ≈ q"3") + } + + property("class with params") = test { + val pName1 = TermName("x1") + val pName2 = TermName("x2") + val q"{class $_($param1)(..$params2)}" = typecheck(q"class Test(val x0: Float)(val $pName1: Int = 3, $pName2: String)") + + val List(p1, p2, _*) = params2 + + assert(p1.name == pName1) + assert(p2.name == pName2) + assert(params2.size == 2) + } + + property("implicit class") = test { + val clName = TypeName("Test") + val paramName = TermName("x") + val q"{implicit class $name($param)}" = typecheck(q"implicit class $clName(val $paramName: String)") + + assert(name == clName) + assert(param.name == paramName) + } + + property("block with lazy") = test { + val lazyName = TermName("x") + val lazyRhsVal = 42 + val lazyRhs = Literal(Constant(lazyRhsVal)) + val q"{lazy val $pname = $rhs}" = typecheck(q"{lazy val $lazyName = $lazyRhsVal}") + + assert(pname == lazyName) + assert(rhs ≈ lazyRhs) + } + + property("class with lazy") = test { + val clName = TypeName("Test") + val paramName = TermName("x") + val q"class $name{lazy val $pname = $_}" = typecheck(q"class $clName {lazy val $paramName = 42}") + + assert(name == clName) + assert(pname == paramName) + } + + property("case class with object") = test { + val defName = TermName("z") + val defRhsVal = 42 + val defRhs = Literal(Constant(defRhsVal)) + val q"object $_{ $_; object $_ extends ..$_ {def $name = $rhs} }" = + typecheck(q""" + object Test{ + case class C(x: Int) { def y = x }; + object C { def $defName = $defRhsVal } + }""") + + assert(name == defName) + assert(rhs ≈ defRhs) + } } |