Skip to content

Fix wildcard protos #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
5 changes: 4 additions & 1 deletion src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/conformsWild.scala
Original file line number Diff line number Diff line change
@@ -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)

}