Skip to content

Commit fed30e1

Browse files
authored
Merge pull request #2763 from dotty-staging/fix-2749
Fix #2749: support implicit resolution of implicit function types
2 parents 04ac312 + 9ae3a1f commit fed30e1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ object Implicits {
6060

6161
/** Return those references in `refs` that are compatible with type `pt`. */
6262
protected def filterMatching(pt: Type)(implicit ctx: Context): List[Candidate] = track("filterMatching") {
63+
val ptNorm = normalize(pt, pt) // `pt` could be implicit function types, check i2749
6364

6465
def refMatches(ref: TermRef)(implicit ctx: Context) = /*ctx.traceIndented(i"refMatches $ref $pt")*/ {
6566

@@ -123,7 +124,8 @@ object Implicits {
123124
record("discarded eligible")
124125
false
125126
}
126-
else NoViewsAllowed.isCompatible(normalize(ref, pt), pt)
127+
else
128+
NoViewsAllowed.isCompatible(normalize(ref, pt), ptNorm)
127129
}
128130
}
129131

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16551655
if (defn.isImplicitFunctionType(pt) &&
16561656
xtree.isTerm &&
16571657
!untpd.isImplicitClosure(xtree) &&
1658+
!ctx.mode.is(Mode.ImplicitShadowing) &&
16581659
!ctx.isAfterTyper)
16591660
makeImplicitFunction(xtree, pt)
16601661
else xtree match {

tests/pos/i2749.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
object Test {
2+
val f: implicit (implicit Int => Char) => Boolean = ???
3+
implicit val n: Int = 3
4+
implicit val g: implicit Int => Char = ???
5+
6+
f : Boolean
7+
}
8+
9+
object Test2 {
10+
val f: implicit (implicit Int => Char) => Boolean = ???
11+
implicit val s: String = null
12+
implicit val g: implicit Int => implicit String => Char = ???
13+
14+
f : Boolean
15+
}
16+
17+
object Test3 {
18+
val f: implicit (implicit Int => implicit String => Char) => Boolean = ???
19+
implicit val n: Int = 3
20+
implicit val g: implicit Int => Char = ???
21+
22+
f : Boolean
23+
}

0 commit comments

Comments
 (0)