summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala7
-rw-r--r--test/files/pos/t7818.scala10
2 files changed, 16 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
index bc54054028..e0c0cd0fdb 100644
--- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
@@ -231,9 +231,14 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
.substituteThis(origThis, extensionThis)
.changeOwner(origMeth -> extensionMeth)
)
+ val castBody =
+ if (extensionBody.tpe <:< extensionMono.finalResultType)
+ extensionBody
+ else
+ gen.mkCastPreservingAnnotations(extensionBody, extensionMono.finalResultType) // SI-7818 e.g. mismatched existential skolems
// Record the extension method ( FIXME: because... ? )
- extensionDefs(companion) += atPos(tree.pos)(DefDef(extensionMeth, extensionBody))
+ extensionDefs(companion) += atPos(tree.pos)(DefDef(extensionMeth, castBody))
// These three lines are assembling Foo.bar$extension[T1, T2, ...]($this)
// which leaves the actual argument application for extensionCall.
diff --git a/test/files/pos/t7818.scala b/test/files/pos/t7818.scala
new file mode 100644
index 0000000000..77b99e7d5d
--- /dev/null
+++ b/test/files/pos/t7818.scala
@@ -0,0 +1,10 @@
+class Observable1[+T](val asJava: JObservable[_ <: T]) extends AnyVal {
+ private def foo[X](a: JObservable[X]): JObservable[X] = ???
+ // was generating a type error as the type of the RHS included an existential
+ // skolem based on the class type parameter `T`, which did not conform
+ // to the typer parameter of the extension method into which the RHS is
+ // transplanted.
+ def synchronize: Observable1[T] = new Observable1(foo(asJava))
+}
+
+class JObservable[T]