Skip to content

Commit 3ae1bc8

Browse files
authored
Merge pull request #6955 from dotty-staging/fix-#6705
Fix #6705: Improve adaptation of overloaded terms
2 parents b3fac38 + 311b726 commit 3ae1bc8

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ object ProtoTypes {
222222
class UnapplySelectionProto(name: Name) extends SelectionProto(name, WildcardType, NoViewsAllowed, true)
223223

224224
trait ApplyingProto extends ProtoType // common trait of ViewProto and FunProto
225-
trait FunOrPolyProto extends ProtoType // common trait of PolyProto and FunProto
225+
trait FunOrPolyProto extends ProtoType { // common trait of PolyProto and FunProto
226+
def isGivenApply: Boolean = false
227+
}
226228

227229
class FunProtoState {
228230

@@ -244,7 +246,7 @@ object ProtoTypes {
244246
* [](args): resultType
245247
*/
246248
case class FunProto(args: List[untpd.Tree], resType: Type)(typer: Typer,
247-
val isGivenApply: Boolean, state: FunProtoState = new FunProtoState)(implicit val ctx: Context)
249+
override val isGivenApply: Boolean, state: FunProtoState = new FunProtoState)(implicit val ctx: Context)
248250
extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
249251
override def resultType(implicit ctx: Context): Type = resType
250252

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,18 +2426,26 @@ class Typer extends Namer
24262426
case alt :: Nil =>
24272427
readaptSimplified(tree.withType(alt))
24282428
case Nil =>
2429+
// If alternative matches, there are still two ways to recover:
2430+
// 1. If context is an application, try to insert an apply or implicit
2431+
// 2. If context is not an application, pick a alternative that does
2432+
// not take parameters.
24292433
def noMatches =
24302434
errorTree(tree, NoMatchingOverload(altDenots, pt)(err))
24312435
def hasEmptyParams(denot: SingleDenotation) = denot.info.paramInfoss == ListOfNil
24322436
pt match {
2433-
case pt: FunProto if !pt.isGivenApply =>
2434-
// insert apply or convert qualifier only for a regular application
2437+
case pt: FunOrPolyProto if !pt.isGivenApply =>
2438+
// insert apply or convert qualifier, but only for a regular application
24352439
tryInsertApplyOrImplicit(tree, pt, locked)(noMatches)
24362440
case _ =>
2437-
if (altDenots exists (_.info.paramInfoss == ListOfNil))
2438-
typed(untpd.Apply(untpd.TypedSplice(tree), Nil), pt, locked)
2439-
else
2440-
noMatches
2441+
alts.filter(_.info.isParameterless) match {
2442+
case alt :: Nil => readaptSimplified(tree.withType(alt))
2443+
case _ =>
2444+
if (altDenots exists (_.info.paramInfoss == ListOfNil))
2445+
typed(untpd.Apply(untpd.TypedSplice(tree), Nil), pt, locked)
2446+
else
2447+
noMatches
2448+
}
24412449
}
24422450
case alts =>
24432451
if (tree.tpe.isErroneous || pt.isErroneous) tree.withType(UnspecifiedErrorType)

tests/pos/i6705.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait StringTempl {
2+
def mkString: String
3+
def mkString(x: String): String
4+
}
5+
6+
7+
object Test {
8+
def (x: String) shouldBe(y: String): Boolean = ???
9+
10+
def test(tmpl: StringTempl): Unit = {
11+
tmpl.mkString shouldBe "hello" // error
12+
tmpl.mkString(", world") shouldBe "hello, world"
13+
}
14+
}

0 commit comments

Comments
 (0)