From 5eeee54e1a1419edf40efb9f9928076a143e7cd7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 19 Jul 2016 17:27:20 +0200 Subject: [PATCH 1/3] Allow function prototypes to have wildcards. --- src/dotty/tools/dotc/typer/Typer.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 11a7b6753059..df72f009537a 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -582,7 +582,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit private def decomposeProtoFunction(pt: Type, defaultArity: Int)(implicit ctx: Context): (List[Type], Type) = pt match { case _ if defn.isFunctionType(pt) => - (pt.dealias.argInfos.init, pt.dealias.argInfos.last) + // if expected parameter type(s) are wildcards, approximate from below. + // if expected result type is a wildcard, approximate from above. + // this can type the greatest set of admissible closures. + (pt.dealias.argTypesLo.init, pt.dealias.argTypesHi.last) case SAMType(meth) => val mt @ MethodType(_, paramTypes) = meth.info (paramTypes, mt.resultType) From a8f7e6cf691f96f8e3049be282c4c11b38ac6f71 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 19 Jul 2016 17:27:51 +0200 Subject: [PATCH 2/3] Refine printing of tuple an function types with wildcards --- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index ca62827afe4a..bdfce266ca5e 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -96,15 +96,15 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override def toText(tp: Type): Text = controlled { def toTextTuple(args: List[Type]): Text = - "(" ~ toTextGlobal(args, ", ") ~ ")" + "(" ~ Text(args.map(argText), ", ") ~ ")" def toTextFunction(args: List[Type]): Text = changePrec(GlobalPrec) { val argStr: Text = if (args.length == 2 && !defn.isTupleType(args.head)) - atPrec(InfixPrec) { toText(args.head) } + atPrec(InfixPrec) { argText(args.head) } else toTextTuple(args.init) - argStr ~ " => " ~ toText(args.last) + argStr ~ " => " ~ argText(args.last) } homogenize(tp) match { case AppliedType(tycon, args) => From 50c75f0c506799b7805ea0276cc21edfe806abe3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 19 Jul 2016 17:47:40 +0200 Subject: [PATCH 3/3] Add test case --- tests/pos/conformsWild.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/pos/conformsWild.scala diff --git a/tests/pos/conformsWild.scala b/tests/pos/conformsWild.scala new file mode 100644 index 000000000000..cfc10d92df47 --- /dev/null +++ b/tests/pos/conformsWild.scala @@ -0,0 +1,11 @@ +object Test { + + val x: Function1[_, _] = (x: String) => 1 + + val y: Function1[_, _] = x => 1 + val y0: Function1[_, _] = x => x + val y1: Function1[_, Nothing] = x => x + + val z: (_, _) = (1, 2) + +}