Skip to content

Commit 0536d1f

Browse files
authored
Merge pull request #1402 from dotty-staging/fix-wildcard-protos
Fix wildcard protos
2 parents 2193100 + 50c75f0 commit 0536d1f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
9696

9797
override def toText(tp: Type): Text = controlled {
9898
def toTextTuple(args: List[Type]): Text =
99-
"(" ~ toTextGlobal(args, ", ") ~ ")"
99+
"(" ~ Text(args.map(argText), ", ") ~ ")"
100100
def toTextFunction(args: List[Type]): Text =
101101
changePrec(GlobalPrec) {
102102
val argStr: Text =
103103
if (args.length == 2 && !defn.isTupleType(args.head))
104-
atPrec(InfixPrec) { toText(args.head) }
104+
atPrec(InfixPrec) { argText(args.head) }
105105
else
106106
toTextTuple(args.init)
107-
argStr ~ " => " ~ toText(args.last)
107+
argStr ~ " => " ~ argText(args.last)
108108
}
109109
homogenize(tp) match {
110110
case AppliedType(tycon, args) =>

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
582582

583583
private def decomposeProtoFunction(pt: Type, defaultArity: Int)(implicit ctx: Context): (List[Type], Type) = pt match {
584584
case _ if defn.isFunctionType(pt) =>
585-
(pt.dealias.argInfos.init, pt.dealias.argInfos.last)
585+
// if expected parameter type(s) are wildcards, approximate from below.
586+
// if expected result type is a wildcard, approximate from above.
587+
// this can type the greatest set of admissible closures.
588+
(pt.dealias.argTypesLo.init, pt.dealias.argTypesHi.last)
586589
case SAMType(meth) =>
587590
val mt @ MethodType(_, paramTypes) = meth.info
588591
(paramTypes, mt.resultType)

tests/pos/conformsWild.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
3+
val x: Function1[_, _] = (x: String) => 1
4+
5+
val y: Function1[_, _] = x => 1
6+
val y0: Function1[_, _] = x => x
7+
val y1: Function1[_, Nothing] = x => x
8+
9+
val z: (_, _) = (1, 2)
10+
11+
}

0 commit comments

Comments
 (0)