diff options
author | Martin Odersky <odersky@gmail.com> | 2016-07-11 18:05:36 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-07-12 18:14:04 +0200 |
commit | cdebd91712b36b048233d7cf9501cc7a5bb50b31 (patch) | |
tree | 35d3ee5d8800e958640916cd0145def1f5726751 /tests/pos | |
parent | 1792c9e9bcff1feba7b50a24a46e1e20d8a39d9b (diff) | |
download | dotty-cdebd91712b36b048233d7cf9501cc7a5bb50b31.tar.gz dotty-cdebd91712b36b048233d7cf9501cc7a5bb50b31.tar.bz2 dotty-cdebd91712b36b048233d7cf9501cc7a5bb50b31.zip |
Allow definition of new types in refinements
Allow definition of types in refinements that do not appear
in parent type.
Diffstat (limited to 'tests/pos')
-rw-r--r-- | tests/pos/t2712-2.scala | 25 | ||||
-rw-r--r-- | tests/pos/t2712-5.scala | 29 |
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/pos/t2712-2.scala b/tests/pos/t2712-2.scala new file mode 100644 index 000000000..95172545d --- /dev/null +++ b/tests/pos/t2712-2.scala @@ -0,0 +1,25 @@ +package test + +// See: https://github.com/milessabin/si2712fix-demo/issues/3 +object Test { + trait A[T1, T2] { } + trait B[T1, T2] { } + class C[T] extends A[T, Long] with B[T, Double] + class CB extends A[Boolean, Long] with B[Boolean, Double] + + trait A2[T] + trait B2[T] + class C2[T] extends A2[T] with B2[T] + class CB2 extends A2[Boolean] with B2[Boolean] + + def meh[M[_], A](x: M[A]): M[A] = x + + val m0 = meh(new C[Boolean]) + m0: C[Boolean] + val m1 = meh(new CB) + m1: B[Boolean, Double] // note: different order in which parents are visited for hk type inference. Dotty picks libearization order. + val m2 = meh(new C2[Boolean]) + m2: C2[Boolean] + val m3 = meh(new CB2) + m3: B2[Boolean] // note: different order in which parents are visited for hk type inference. Dotty picks libearization order. +} diff --git a/tests/pos/t2712-5.scala b/tests/pos/t2712-5.scala new file mode 100644 index 000000000..ed96d4c06 --- /dev/null +++ b/tests/pos/t2712-5.scala @@ -0,0 +1,29 @@ +package test + +import scala.language.higherKinds + +trait Functor[F[_]] { + def map[A, B](f: A => B, fa: F[A]): F[B] +} + +object Functor { + implicit def function[A]: Functor[({ type l[B] = A => B })#l] = + new Functor[({ type l[B] = A => B })#l] { + def map[C, B](cb: C => B, ac: A => C): A => B = cb compose ac + } +} + +object FunctorSyntax { + implicit class FunctorOps[F[_], A](fa: F[A])(implicit F: Functor[F]) { + def map[B](f: A => B): F[B] = F.map(f, fa) + } +} + +object Test { + + val f: Int => String = _.toString + + import FunctorSyntax._ + + f.map((s: String) => s.reverse) +} |