From 26a5bcbbd935903989a22e631f5325a067acd7a2 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 5 Feb 2016 00:35:43 +0100 Subject: [PATCH] Fix #1044: Properly constrain polymorphic implicit views When `wildApprox` encounters a PolyParam it approximates it by its bounds in the current constraint set, this only makes sense if we have added the PolyType corresponding to this PolyParam to the constrain set using `ProtoTypes#constrained`, otherwise, we might get the bounds of another use of this `PolyType`. This is exactly what happened in i1044.scala: to compile, the implicit view `refArrayOps` needs to be used twice with two different type parameters. The fix is to always constrain polymorphic implicit views before calling `wildApprox` on their result type. This fix was inspired by the approach of #1054. --- src/dotty/tools/dotc/typer/Implicits.scala | 2 +- tests/pos/i1044.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i1044.scala diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index 280cc40e944e..691b76ec66a8 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -52,7 +52,7 @@ object Implicits { mt.paramTypes.length != 1 || !(argType relaxed_<:< mt.paramTypes.head)(ctx.fresh.setExploreTyperState) case poly: PolyType => - poly.resultType match { + constrained(poly).resultType match { case mt: MethodType => mt.isImplicit || mt.paramTypes.length != 1 || diff --git a/tests/pos/i1044.scala b/tests/pos/i1044.scala new file mode 100644 index 000000000000..a984dbd67449 --- /dev/null +++ b/tests/pos/i1044.scala @@ -0,0 +1,3 @@ +object Test { + val x = ???.getClass.getMethods.head.getParameterTypes.mkString(",") +}