Skip to content

Commit fc79397

Browse files
committed
Allow auto-tupling for arguments to overloaded methods
If all overloaded variants of a method are uniary, we should also allow auto-tupling. This is necessary to make overloaded `==' methods work in cases like: xs == (1, 2)
1 parent cec6467 commit fc79397

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,14 +1469,22 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
14691469
}
14701470
}
14711471

1472-
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match {
1473-
case _: MethodType | _: PolyType =>
1474-
def isUnary = wtp.firstParamTypes match {
1472+
def isUnary(tp: Type): Boolean = tp match {
1473+
case tp: MethodicType =>
1474+
tp.firstParamTypes match {
14751475
case ptype :: Nil => !ptype.isRepeatedParam
14761476
case _ => false
14771477
}
1478-
if (pt.args.lengthCompare(1) > 0 && isUnary && ctx.canAutoTuple)
1479-
adaptToArgs(wtp, pt.tupled)
1478+
case tp: TermRef =>
1479+
tp.denot.alternatives.forall(alt => isUnary(alt.info))
1480+
case _ =>
1481+
false
1482+
}
1483+
1484+
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match {
1485+
case _: MethodType | _: PolyType =>
1486+
if (pt.args.lengthCompare(1) > 0 && isUnary(wtp) && ctx.canAutoTuple)
1487+
adaptInterpolated(tree, pt.tupled, original)
14801488
else
14811489
tree
14821490
case _ => tryInsertApplyOrImplicit(tree, pt) {
@@ -1684,7 +1692,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16841692
case ErrorType =>
16851693
tree
16861694
case ref: TermRef =>
1687-
adaptOverloaded(ref)
1695+
pt match {
1696+
case pt: FunProto
1697+
if pt.args.lengthCompare(1) > 0 && isUnary(ref) && ctx.canAutoTuple =>
1698+
adaptInterpolated(tree, pt.tupled, original)
1699+
case _ =>
1700+
adaptOverloaded(ref)
1701+
}
16881702
case poly: PolyType =>
16891703
if (pt.isInstanceOf[PolyProto]) tree
16901704
else {

0 commit comments

Comments
 (0)