From 671e6e03c7e096eda0c27262ae8605fa7af76f59 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 12 Sep 2013 13:28:06 -0700 Subject: Corrects behavior of finalResultType. The implementation had come to depend on finalResultType accidentally doing things beyond its charter - in particular, widening types. After hunting down and fixing the call sites depending on the bugs, I was able to rewrite the method to do only what it's supposed to do. I threw in a different way of writing it entirely to suggest how some correctness might be obtained in the future. It's a lot harder for a method written like this to break. --- test/files/pos/infersingle.scala | 51 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'test/files/pos/infersingle.scala') diff --git a/test/files/pos/infersingle.scala b/test/files/pos/infersingle.scala index 6830fcd799..60f4ff07e6 100644 --- a/test/files/pos/infersingle.scala +++ b/test/files/pos/infersingle.scala @@ -1,5 +1,52 @@ -object Test { +object Test1 { def one[T](x: T): Option[T] = Some(x) val x = "one" val y: Option[x.type] = one(x) -} \ No newline at end of file +} + +object Test2 { + // Has never worked, but seems desirable given the recent changes to + // pattern type inference. + val a = "" + object Id { + def unapply(xxxx: Any): Some[a.type] = Some[a.type](a) + } + val b: a.type = (a: a.type) match { + case Id(x) => x + } +} + +object Test3 { + val a = "" + object Id { + def unapply(xxxx: Any): Some[Test3.type] = Some[Test3.type](Test3) + } + val b: Test3.type = a match { + case Id(x) => x + } +} + +class Test4 { + val a = "" + object Id { + def unapply(xxxx: Any): Some[Test4.this.type] = Some[Test4.this.type](Test4.this) + } + val b: Test4.this.type = a match { + case Id(x) => x + } +} + +class Super5 { + final val q = "" + def q1: q.type = q +} + +class Test5 extends Super5 { + val a = "" + object Id { + def unapply(xxxx: Any): Some[Test5.super.q.type] = Some[Test5.super.q.type](q1) + } + val b: Test5.super.q.type = a match { + case Id(x) => x + } +} -- cgit v1.2.3