From 5421dec9b42fb95ad56696d1ddb3ed2b7abac50f Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 18 Oct 2017 17:08:23 +0200 Subject: [PATCH] Fix #2732: Allow wildcards in SAM types The `isInstantiable` test as written is incorrect: Given tp = `java.util.function.Function[String, _ <: String]`, we will have: tref = skolem TermRef with underlying info `tp` selfType = `java.util.function.Function[String, tref#R]` (because of the `asSeenFrom`) `tref <:< selfType` is false, because `tref.underlying` is just `tp` and its return type parameter is a bounded wildcard, not a reference with `tref` as a prefix. In any case, I cannot think of a case where this function should return false, and no test failed when I removed it. So I'm removing it until someone can come up with a counter-example. --- compiler/src/dotty/tools/dotc/core/Types.scala | 10 +--------- tests/pos/i2732.scala | 8 ++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 tests/pos/i2732.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8c6c641a5784..c11959e28645 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3717,16 +3717,8 @@ object Types { case _ => NoType } - def isInstantiatable(tp: Type)(implicit ctx: Context): Boolean = zeroParamClass(tp) match { - case cinfo: ClassInfo => - val tref = tp.narrow - val selfType = cinfo.selfType.asSeenFrom(tref, cinfo.cls) - tref <:< selfType - case _ => - false - } def unapply(tp: Type)(implicit ctx: Context): Option[SingleDenotation] = - if (isInstantiatable(tp)) { + if (zeroParamClass(tp).exists) { val absMems = tp.abstractTermMembers // println(s"absMems: ${absMems map (_.show) mkString ", "}") if (absMems.size == 1) diff --git a/tests/pos/i2732.scala b/tests/pos/i2732.scala new file mode 100644 index 000000000000..f693bc6e2973 --- /dev/null +++ b/tests/pos/i2732.scala @@ -0,0 +1,8 @@ +object Foo { + // Example 1 + val fun: java.util.function.Function[String, _ <: String] = x => x + + // Example 2 + val map = new java.util.HashMap[String, String] + map.computeIfAbsent("hello", foo => "world") +}