diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index f0788665ca17..a9a75735c7e0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -60,6 +60,7 @@ object Implicits { /** Return those references in `refs` that are compatible with type `pt`. */ protected def filterMatching(pt: Type)(implicit ctx: Context): List[Candidate] = track("filterMatching") { + val ptNorm = normalize(pt, pt) // `pt` could be implicit function types, check i2749 def refMatches(ref: TermRef)(implicit ctx: Context) = /*ctx.traceIndented(i"refMatches $ref $pt")*/ { @@ -123,7 +124,8 @@ object Implicits { record("discarded eligible") false } - else NoViewsAllowed.isCompatible(normalize(ref, pt), pt) + else + NoViewsAllowed.isCompatible(normalize(ref, pt), ptNorm) } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 974c9786799a..632acca1f00d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1640,6 +1640,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (defn.isImplicitFunctionType(pt) && xtree.isTerm && !untpd.isImplicitClosure(xtree) && + !ctx.mode.is(Mode.ImplicitShadowing) && !ctx.isAfterTyper) makeImplicitFunction(xtree, pt) else xtree match { diff --git a/tests/pos/i2749.scala b/tests/pos/i2749.scala new file mode 100644 index 000000000000..5d4972421ebb --- /dev/null +++ b/tests/pos/i2749.scala @@ -0,0 +1,23 @@ +object Test { + val f: implicit (implicit Int => Char) => Boolean = ??? + implicit val n: Int = 3 + implicit val g: implicit Int => Char = ??? + + f : Boolean +} + +object Test2 { + val f: implicit (implicit Int => Char) => Boolean = ??? + implicit val s: String = null + implicit val g: implicit Int => implicit String => Char = ??? + + f : Boolean +} + +object Test3 { + val f: implicit (implicit Int => implicit String => Char) => Boolean = ??? + implicit val n: Int = 3 + implicit val g: implicit Int => Char = ??? + + f : Boolean +}