diff options
Diffstat (limited to 'test')
9 files changed, 173 insertions, 21 deletions
diff --git a/test/files/neg/divergent-implicit.check b/test/files/neg/divergent-implicit.check index 60d876409f..d4a3ddfc71 100644 --- a/test/files/neg/divergent-implicit.check +++ b/test/files/neg/divergent-implicit.check @@ -3,6 +3,10 @@ divergent-implicit.scala:4: error: type mismatch; required: String val x1: String = 1 ^ +divergent-implicit.scala:5: error: diverging implicit expansion for type Int => String +starting with method $conforms in object Predef + val x2: String = cast[Int, String](1) + ^ divergent-implicit.scala:14: error: type mismatch; found : Test2.Foo required: Test2.Bar @@ -13,4 +17,4 @@ divergent-implicit.scala:15: error: type mismatch; required: Test2.Bar val y: Bar = new Baz ^ -three errors found +four errors found diff --git a/test/files/pos/t8460.scala b/test/files/pos/t8460.scala new file mode 100644 index 0000000000..10d2ed432c --- /dev/null +++ b/test/files/pos/t8460.scala @@ -0,0 +1,25 @@ +object tan extends UFunc { + implicit def ImplDouble: Impl[Double, Double] = ??? +} + +trait UFunc { + trait TC[+A] + type Impl[V, VR] = UFunc.UImpl[this.type, V, VR] +} + +object UFunc { + class UImpl[A, B, C] + implicit def implicitDoubleUTag[Tag, V, VR](implicit conv: V=>Double, impl: UImpl[Tag, Double, VR]):UImpl[Tag, V, VR] = ??? + +} + +object Test { + implicitly[tan.Impl[Double, Double]] + // we should discard the one and only divergent implicit (`implicitDoubleUTag`) + // This is done under `scalac-hash v2.10.4 test.scala`, but not under + // `scalac-hash v2.10.4 -Xdivergence211 test.scala` + // + // This seems to be because the companion implicits contain redundant entries + // + +} diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala index 69aef12668..fd810674f5 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala @@ -90,6 +90,15 @@ trait ClassConstruction { self: QuasiquoteProperties => val args = q"val a: Int; val b: Int" assertEqAst(q"class C(implicit ..$args)", "class C(implicit val a: Int, val b: Int)") } + + property("SI-8451: inline secondary constructors") = test { + assertEqAst(q"class C(x: Int) { def this() = this(0) }", "class C(x: Int) { def this() = this(0) }") + } + + property("SI-8451: unquoted secondary constructors") = test { + val secondaryCtor = q"def this() = this(0)" + assertEqAst(q"class C(x: Int) { $secondaryCtor }", "class C(x: Int) { def this() = this(0) }") + } } trait TraitConstruction { self: QuasiquoteProperties => diff --git a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala index af7f2164a0..2c0e100b5a 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala @@ -229,6 +229,12 @@ trait DefDeconstruction { self: QuasiquoteProperties => val q"def foo(...$argss)(implicit ..$impl)" = q"def foo(x: Int)" assert(impl.isEmpty) } + + property("SI-8451") = test { + val q"def this(..$params) = this(..$args)" = q"def this(x: Int) = this(0)" + assert(params ≈ List(q"${Modifiers(PARAM)} val x: Int")) + assert(args ≈ List(q"0")) + } } trait ImportDeconstruction { self: QuasiquoteProperties => diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/files/scalacheck/quasiquotes/ErrorProps.scala index 9137fe17d8..2cba07abf2 100644 --- a/test/files/scalacheck/quasiquotes/ErrorProps.scala +++ b/test/files/scalacheck/quasiquotes/ErrorProps.scala @@ -195,6 +195,19 @@ object ErrorProps extends QuasiquoteProperties("errors") { q"f(..$l)" """) + property("SI-8451 construction: disallow everything except for constructor calls in secondary constructor bodies") = fails( + "'this' expected but unquotee found", + """ + val rhs1 = q"this(0)" + val ctor1 = q"def this(x: Int) = $rhs1" + """) + + property("SI-8451 deconstruction: disallow everything except for constructor calls in secondary constructor bodies") = fails( + "'this' expected but unquotee found", + """ + val q"def this(..$params) = $rhs2" = q"def this(x: Int) = this(0)" + """) + // // Make sure a nice error is reported in this case // { import Flag._; val mods = NoMods; q"lazy $mods val x: Int" } } diff --git a/test/files/scalacheck/quasiquotes/LiftableProps.scala b/test/files/scalacheck/quasiquotes/LiftableProps.scala index 29fdea5c89..a4c57ac359 100644 --- a/test/files/scalacheck/quasiquotes/LiftableProps.scala +++ b/test/files/scalacheck/quasiquotes/LiftableProps.scala @@ -164,4 +164,11 @@ object LiftableProps extends QuasiquoteProperties("liftable") { val right3: Either[Int, Int] = Right(1) assert(q"$right3" ≈ q"scala.util.Right(1)") } + + property("lift xml comment") = test { + implicit val liftXmlComment = Liftable[xml.Comment] { comment => + q"new _root_.scala.xml.Comment(${comment.commentText})" + } + assert(q"${xml.Comment("foo")}" ≈ q"<!--foo-->") + } } diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala index 9e60729c09..49ffaff630 100644 --- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala @@ -222,4 +222,28 @@ object TermDeconstructionProps extends QuasiquoteProperties("term deconstruction val q"{ case ..$cases }" = q"{ case a => b case c => d }" val List(cq"a => b", cq"c => d") = cases } + + property("SI-8350 `new C` and `new C()` are equivalent") = test { + val q"new C" = q"new C()" + val q"new C()" = q"new C" + } + + property("SI-8350 new applications extracted only for non-empty ctor calls") = test{ + val q"new $c1" = q"new C()" + assert(c1 ≈ tq"C") + val q"new $c2" = q"new C(x)" + assert(c2 ≈ q"${tq"C"}(x)") + } + + property("SI-8350 original test case") = test { + val q"new ..$parents" = q"new Foo with Bar" + assert(parents ≈ List(tq"Foo", tq"Bar")) + } + + property("SI-8387 new is not an application") = test { + val `new` = q"new F(x)" + val q"$f(...$argss)" = `new` + assert(f ≈ `new`) + assert(argss.isEmpty) + } } diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala index fb2eb69321..a5d526191f 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -2,32 +2,13 @@ import org.scalacheck._, Prop._, Gen._, Arbitrary._ import scala.reflect.runtime.universe._, Flag._, internal.reificationSupport._ object TypecheckedProps extends QuasiquoteProperties("typechecked") { - def original(tree: Tree) = tree match { - case tt: TypeTree => Some(tt.original) - case _ => None - } - def originals(trees: List[Tree]) = trees.flatMap(original) - val int = ScalaDot(TypeName("Int")) - val intint = List(int, int) + property("tuple term") = test { val q"(..$elements)" = typecheck(q"(1, 2)") assert(elements ≈ List(q"1", q"2")) } - property("tuple type") = test { - val tq"(..$els0)" = typecheckTyp(tq"Unit") - assert(els0.isEmpty) - val tq"(..$els1)" = typecheckTyp(tq"(Int, Int)") - assert(originals(els1) ≈ intint) - } - - property("function type") = test { - val tq"(..$argtpes) => $restpe" = typecheckTyp(tq"(Int, Int) => Int") - assert(originals(argtpes) ≈ intint) - assert(original(restpe).get ≈ int) - } - property("for/for-yield") = test { val enums = fq"x <- xs" :: fq"x1 = x + 1" :: fq"if x1 % 2 == 0" :: Nil val body = q"x1" @@ -158,3 +139,78 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { assert(cases ≈ q"{ case 1 => () }".cases) } } + +trait TypecheckedTypes { self: QuasiquoteProperties => + property("type ident") = test { + val q"$_; type $_ = $tpt" = typecheck(q"class C; type T = C") + val tq"C" = tpt + } + + property("type select") = test { + val tq"scala.Int" = typecheckTyp(tq"Int") + } + + property("this type select") = test { + val q"class $_ { $_; type $_ = $tpt }" = typecheck(q"class C { type A = Int; type B = this.A }") + val tq"this.$name" = tpt + val TypeName("A") = name + } + + property("super type select") = test { + val q"$_; class $_ extends $_ { type $_ = $tpt }" = + typecheck(q"class C1 { type A = Int }; class C2 extends C1 { type B = super[C1].A }") + val tq"$empty.super[$c1].$a" = tpt + val TypeName("") = empty + val TypeName("C1") = c1 + val TypeName("A") = a + } + + property("applied type") = test { + val tt = typecheckTyp(q"Map[Int, Int]") + val tq"$tpt[..$tpts]" = tt + val tq"scala.this.Predef.Map" = tpt + val List(tq"scala.Int", tq"scala.Int") = tpts + } + + property("tuple type") = test { + val tq"(..$els0)" = typecheckTyp(tq"Unit") + assert(els0.isEmpty) + val tq"(..$els1)" = typecheckTyp(tq"(Int, Int)") + val List(tq"scala.Int", tq"scala.Int") = els1 + } + + property("function type") = test { + val tq"(..$argtpes) => $restpe" = typecheckTyp(tq"(Int, Int) => Int") + val List(tq"scala.Int", tq"scala.Int") = argtpes + val tq"scala.Int" = restpe + } + + property("compound type") = test { + val tq"..$parents { ..$defns }" = typecheckTyp(tq"Int { def x: Int }") + val List(tq"Int") = parents + val List(q"def x: Int") = defns + } + + property("singleton type") = test { + val tq"$ref.type" = typecheckTyp(tq"scala.Predef.type") + val q"scala.Predef" = ref + } + + property("type projection") = test { + val tq"$tpt#$name" = typecheckTyp(tq"({ type T = Int })#T") + val TypeName("T") = name + val tq"{ type T = Int }" = tpt + } + + property("annotated type") = test { + val tq"$tpt @$annot" = typecheckTyp(tq"Int @unchecked") + val tq"scala.Int" = tpt + val q"new unchecked" = annot + } + + property("existential type") = test { + val tq"$tpt forSome { ..$defns }" = typecheckTyp(tq"T forSome { type T }") + val tq"T" = tpt + val q"type T" :: Nil = defns + } +} diff --git a/test/files/scalacheck/quasiquotes/UnliftableProps.scala b/test/files/scalacheck/quasiquotes/UnliftableProps.scala index 1d7629aa29..659b18edab 100644 --- a/test/files/scalacheck/quasiquotes/UnliftableProps.scala +++ b/test/files/scalacheck/quasiquotes/UnliftableProps.scala @@ -155,4 +155,12 @@ object UnliftableProps extends QuasiquoteProperties("unliftable") { assert(t21 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)) assert(t22 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)) } + + property("unlift xml comment") = test { + implicit val unliftXmlComment = Unliftable[xml.Comment] { + case q"new _root_.scala.xml.Comment(${value: String})" => xml.Comment(value) + } + val q"${comment: xml.Comment}" = q"<!--foo-->" + assert(comment.commentText == "foo") + } } |