Skip to content

Commit 4261c6a

Browse files
committed
address review
1 parent af60bad commit 4261c6a

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,14 +716,16 @@ trait Implicits { self: Typer =>
716716
)
717717
val userDefined = maybeAnnot.flatMap { case (annot, alt) =>
718718
val params = alt.ref.underlying match {
719-
case lambda: TypeLambda => lambda.typeParams.map(_.paramName.unexpandedName.toString)
720-
case _ => Nil
719+
case p: PolyType => p.paramNames.map(_.toString)
720+
case _ => Nil
721721
}
722+
def resolveTypes(targs: List[Tree])(implicit ctx: Context) =
723+
targs.map(a => fullyDefinedType(a.tpe, "type argument", a.pos))
722724
val args = alt.tree match {
723-
case TypeApply(_, targs) if params.nonEmpty =>
724-
def resolveTypes(targs: List[tpd.Tree])(implicit ctx: Context) =
725-
targs.map(a => fullyDefinedType(a.tpe, "type parameter", a.pos))
725+
case TypeApply(_, targs) =>
726726
resolveTypes(targs)(ctx.fresh.setTyperState(alt.tstate))
727+
case Block(List(DefDef(_, _, _, _, Apply(TypeApply(_, targs), _))), _) =>
728+
resolveTypes(targs.asInstanceOf[List[Tree]])(ctx.fresh.setTyperState(alt.tstate))
727729
case _ =>
728730
Nil
729731
}

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,4 +1385,27 @@ class ErrorMessagesTests extends ErrorMessagesTest {
13851385

13861386
assertEquals(m.msg, "Could not prove Int =!= Int")
13871387
}
1388+
1389+
@Test def userDefinedImplicitAmbiguous4 =
1390+
checkMessagesAfter("frontend") {
1391+
"""
1392+
|class C {
1393+
| @annotation.implicitAmbiguous("msg A=${A}")
1394+
| implicit def f[A](x: Int): String = "f was here"
1395+
| implicit def g(x: Int): String = "f was here"
1396+
| def test: Unit = {
1397+
| implicitly[Int => String]
1398+
| }
1399+
|}
1400+
1401+
""".stripMargin
1402+
}.expect { (itcx, messages) =>
1403+
import diagnostic.NoExplanation
1404+
implicit val ctx: Context = itcx
1405+
1406+
assertMessageCount(1, messages)
1407+
val (m: NoExplanation) :: Nil = messages
1408+
1409+
assertEquals(m.msg, "msg A=Any")
1410+
}
13881411
}

0 commit comments

Comments
 (0)