aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2017-03-09 10:20:25 +0100
committerGitHub <noreply@github.com>2017-03-09 10:20:25 +0100
commit8e5c9c4a1a4555883307b7e81fea064134f350f2 (patch)
treee2feee0b87ed785e32ed8ba8fa2953128498f917 /tests/pos
parent6abaa109e1add82f4add605a5cb3243e34b1ee33 (diff)
parentc7f1f35c36593ac9454c8572a59c649610829b6a (diff)
downloaddotty-8e5c9c4a1a4555883307b7e81fea064134f350f2.tar.gz
dotty-8e5c9c4a1a4555883307b7e81fea064134f350f2.tar.bz2
dotty-8e5c9c4a1a4555883307b7e81fea064134f350f2.zip
Merge pull request #2045 from dotty-staging/fix-hlist-hmap
Fix type inference for HLists and HMaps
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/depmet_implicit_norm_ret.scala34
-rw-r--r--tests/pos/t5070.scala23
-rw-r--r--tests/pos/t5643.scala19
3 files changed, 76 insertions, 0 deletions
diff --git a/tests/pos/depmet_implicit_norm_ret.scala b/tests/pos/depmet_implicit_norm_ret.scala
new file mode 100644
index 000000000..42bfb9fe1
--- /dev/null
+++ b/tests/pos/depmet_implicit_norm_ret.scala
@@ -0,0 +1,34 @@
+object Test{
+ def ?[S <: AnyRef](implicit w : S) : w.type = w
+
+ // fallback, lower priority (overloading rules apply: pick alternative in subclass lowest in subtyping lattice)
+ class ZipWithDefault {
+ implicit def ZeroZipWith[S]: Test.ZipWith[S]{type T = Stream[S]} = new ZipWith[S] {
+ type T = Stream[S]
+ }
+ }
+
+ object ZipWith extends ZipWithDefault {
+ // def apply[S: ZipWith](s : S) = ?[ZipWith[S]].zipWith(s) // TODO: bug return type should be inferred
+ def apply[S](s : S)(implicit zw: ZipWith[S]): zw.T = zw.zipWith(s)
+
+ implicit def SuccZipWith[S,R](implicit zWith : ZipWith[R]): Test.ZipWith[S => R]{type T = Stream[S] => zWith.T} = new ZipWith[S => R] {
+ type T = Stream[S] => zWith.T // dependent types replace the associated types functionality
+ }
+ }
+
+ import ZipWith._
+
+ trait ZipWith[S] {
+ type T
+ def zipWith : S => T = sys.error("")
+ }
+
+ // bug: inferred return type = (Stream[A]) => java.lang.Object with Test.ZipWith[B]{type T = Stream[B]}#T
+ // this seems incompatible with vvvvvvvvvvvvvvvvvvvvvv -- #3731
+ def map1[A,B](f : A => B) = ZipWith(f)(SuccZipWith) // this typechecks but fails in -Ycheck:first
+ val tst1: Stream[Int] = map1[String, Int]{x: String => x.length}.apply(Stream("a"))
+
+ def map2[A,B](f : A => B) = ZipWith(f) // this finds ZeroZipWith where scalac finds SuccZipWith and fails typechecking in the next line.
+ val tst2: Stream[Int] = map2{x: String => x.length}.apply(Stream("a"))
+}
diff --git a/tests/pos/t5070.scala b/tests/pos/t5070.scala
index 410afba14..0e5c0ffc0 100644
--- a/tests/pos/t5070.scala
+++ b/tests/pos/t5070.scala
@@ -13,3 +13,26 @@ class Test {
implicitly[a.T](b(a)) // works
}
+
+
+class ImplicitVsTypeAliasTezt {
+
+ class Monad[m[_]] {
+ type For[a] = _For[m, a]
+ implicit def toFor[a](m: m[a]): For[a] = throw new Error("todo") // lookup fails
+// implicit def toFor[a](m: m[a]): _For[m, a] = throw new Error("todo") // fine.
+ }
+
+ trait _For[m[_], a] {
+ def map[b](p: a => b): m[b]
+ }
+
+ def useMonad[m[_], a](m: m[a])(implicit i: Monad[m]) = {
+ import i._
+
+ // value map is not a member of type parameter m[a]
+ for {
+ x <- m
+ } yield x.toString
+ }
+}
diff --git a/tests/pos/t5643.scala b/tests/pos/t5643.scala
new file mode 100644
index 000000000..1ce34ba36
--- /dev/null
+++ b/tests/pos/t5643.scala
@@ -0,0 +1,19 @@
+object TupledEvidenceTest {
+
+ abstract class TupledEvidence[M[_], T0] { type T = T0 }
+
+ implicit def witnessTuple2[M[_], T1, T2](implicit ev1: M[T1], ev2: M[T2]):
+ TupledEvidence[M, (T1, T2)] { type T = (T1, T2) } = sys.error("")
+
+ class GetResult[T]
+
+ implicit val getString: GetResult[String] = new GetResult[String]
+
+ implicit def getTuple[T](implicit w: TupledEvidence[GetResult, T]): GetResult[w.T] = sys.error("")
+
+ def f[T : GetResult] = ""
+
+ f[(String,String)](getTuple[(String, String)])
+
+ f[(String,String)]
+}