From 493197fce6c9c493dfa4dcdd8fd5e29bad82d49b Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 3 Dec 2012 13:14:22 +0100 Subject: SI-6443 Widen dependent param types in uncurry Bridge building operates on unusual method signatures: after uncurry, so parameter lists are collapsed; but before erasure, so dependently typed parameters are still around. Original: def foo(a: T)(b: a.type, c: a.U): Unit During computeBridges: (a: T, b: a.type, c: a.U)Unit This signature no longer appears to override the corresponding one in a superclass, because the types of `b` and `c` are dependent on method parameters. The root of the problem is uncurry, which leaves the trees in a poor state. This commit changes uncurry to remedy this. An example illustrates it best: // source def foo(a: A)(b: a.type): b.type = b // post uncurry before this patch. // not well typed code! def foo(a: A, b: a.type): a.type = { // post uncurry after this patch def foo(a: A, b: A): A = { val b$1 = b.asInstanceOf[a.type] b$1 } --- test/files/neg/t6443c.check | 7 +++++++ test/files/neg/t6443c.scala | 21 +++++++++++++++++++++ test/files/run/t6135.scala | 13 +++++++++++++ test/files/run/t6443.scala | 15 +++++++++++++++ test/files/run/t6443b.scala | 16 ++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 test/files/neg/t6443c.check create mode 100644 test/files/neg/t6443c.scala create mode 100644 test/files/run/t6135.scala create mode 100644 test/files/run/t6443.scala create mode 100644 test/files/run/t6443b.scala (limited to 'test/files') diff --git a/test/files/neg/t6443c.check b/test/files/neg/t6443c.check new file mode 100644 index 0000000000..7cf8d23f4b --- /dev/null +++ b/test/files/neg/t6443c.check @@ -0,0 +1,7 @@ +t6443c.scala:16: error: double definition: +method foo:(d: B.D)(a: Any)(d2: d.type)Unit and +method foo:(d: B.D)(a: Any, d2: d.type)Unit at line 11 +have same type after erasure: (d: B.D, a: Object, d2: B.D)Unit + def foo(d: D)(a: Any)(d2: d.type): Unit = () + ^ +one error found diff --git a/test/files/neg/t6443c.scala b/test/files/neg/t6443c.scala new file mode 100644 index 0000000000..817224e043 --- /dev/null +++ b/test/files/neg/t6443c.scala @@ -0,0 +1,21 @@ +trait A { + type D >: Null <: C + def foo(d: D)(a: Any, d2: d.type): Unit + trait C { + def bar: Unit = foo(null)(null, null) + } +} +object B extends A { + class D extends C + + def foo(d: D)(a: Any, d2: d.type): Unit = () // Bridge method required here! + + // No bridge method should be added, but we'll be happy enough if + // the "same type after erasure" error kicks in before the duplicated + // bridge causes a problem. + def foo(d: D)(a: Any)(d2: d.type): Unit = () +} + +object Test extends App { + new B.D().bar +} diff --git a/test/files/run/t6135.scala b/test/files/run/t6135.scala new file mode 100644 index 0000000000..c0f8f3fd1d --- /dev/null +++ b/test/files/run/t6135.scala @@ -0,0 +1,13 @@ +object Test extends App { + class A { class V } + + abstract class B[S] { + def foo(t: S, a: A)(v: a.V) + } + + val b1 = new B[String] { + def foo(t: String, a: A)(v: a.V) = () // Bridge method required here! + } + + b1.foo("", null)(null) +} diff --git a/test/files/run/t6443.scala b/test/files/run/t6443.scala new file mode 100644 index 0000000000..67fe2cab22 --- /dev/null +++ b/test/files/run/t6443.scala @@ -0,0 +1,15 @@ +class Base +class Derived extends Base + +trait A { + def foo(d: String)(d2: d.type): Base + val s = "" + def bar: Unit = foo(s)(s) +} +object B extends A { + def foo(d: String)(d2: d.type): D forSome { type D <: S; type S <: Derived } = {d2.isEmpty; null} // Bridge method required here! +} + +object Test extends App { + B.bar +} diff --git a/test/files/run/t6443b.scala b/test/files/run/t6443b.scala new file mode 100644 index 0000000000..9320b1dcfe --- /dev/null +++ b/test/files/run/t6443b.scala @@ -0,0 +1,16 @@ +trait A { + type D >: Null <: C + def foo(d: D)(d2: d.type): Unit + trait C { + def bar: Unit = foo(null)(null) + } +} +object B extends A { + class D extends C + + def foo(d: D)(d2: d.type): Unit = () // Bridge method required here! +} + +object Test extends App { + new B.D().bar +} -- cgit v1.2.3