Skip to content

Fix #2749: support implicit resolution of implicit function types #2763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")*/ {

Expand Down Expand Up @@ -123,7 +124,8 @@ object Implicits {
record("discarded eligible")
false
}
else NoViewsAllowed.isCompatible(normalize(ref, pt), pt)
else
NoViewsAllowed.isCompatible(normalize(ref, pt), ptNorm)
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions tests/pos/i2749.scala
Original file line number Diff line number Diff line change
@@ -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
}