diff options
author | Martin Odersky <odersky@gmail.com> | 2016-04-22 17:47:57 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-05-23 16:10:42 +0200 |
commit | fc7939724c1a0095cd3044005b47d15b03555c65 (patch) | |
tree | 4204510808ba91373af63cf67011d0b8ee0c5e45 /src/dotty/tools/dotc/typer/Typer.scala | |
parent | cec6467c7a430395e19d24d2700bda72ffab5d36 (diff) | |
download | dotty-fc7939724c1a0095cd3044005b47d15b03555c65.tar.gz dotty-fc7939724c1a0095cd3044005b47d15b03555c65.tar.bz2 dotty-fc7939724c1a0095cd3044005b47d15b03555c65.zip |
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)
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f263d3093..f7fa318cd 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1469,14 +1469,22 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match { - case _: MethodType | _: PolyType => - def isUnary = wtp.firstParamTypes match { + def isUnary(tp: Type): Boolean = tp match { + case tp: MethodicType => + tp.firstParamTypes match { case ptype :: Nil => !ptype.isRepeatedParam case _ => false } - if (pt.args.lengthCompare(1) > 0 && isUnary && ctx.canAutoTuple) - adaptToArgs(wtp, pt.tupled) + case tp: TermRef => + tp.denot.alternatives.forall(alt => isUnary(alt.info)) + case _ => + false + } + + def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match { + case _: MethodType | _: PolyType => + if (pt.args.lengthCompare(1) > 0 && isUnary(wtp) && ctx.canAutoTuple) + adaptInterpolated(tree, pt.tupled, original) else tree case _ => tryInsertApplyOrImplicit(tree, pt) { @@ -1684,7 +1692,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case ErrorType => tree case ref: TermRef => - adaptOverloaded(ref) + pt match { + case pt: FunProto + if pt.args.lengthCompare(1) > 0 && isUnary(ref) && ctx.canAutoTuple => + adaptInterpolated(tree, pt.tupled, original) + case _ => + adaptOverloaded(ref) + } case poly: PolyType => if (pt.isInstanceOf[PolyProto]) tree else { |