Skip to content

Commit

Permalink
Fix #5833: Refine condition what constitutes an IFT in adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Feb 4, 2019
1 parent 537f80d commit 7db38bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2551,9 +2551,17 @@ class Typer extends Namer
missingArgs(wtp)
}

def isImplicitFunctionRef(wtp: Type): Boolean = wtp match {
case RefinedType(parent, nme.apply, _) =>
isImplicitFunctionRef(parent) // apply refinements indicate a dependent IFT
case _ =>
val underlying = wtp.underlyingClassRef(refinementOK = false) // other refinements are not OK
defn.isImplicitFunctionClass(underlying.classSymbol)
}

def adaptNoArgsOther(wtp: Type): Tree = {
ctx.typeComparer.GADTused = false
if (defn.isImplicitFunctionClass(wtp.underlyingClassRef(refinementOK = false).classSymbol) &&
if (isImplicitFunctionRef(wtp) &&
!untpd.isContextualClosure(tree) &&
!isApplyProto(pt) &&
!ctx.mode.is(Mode.Pattern) &&
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i5833.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object Dependent{
def x: given (i: Int) => Int = ???
def y: given (i: Int) => Int = x
}
object Independent{
def x: given Int => Int = ???
def y: given Int => Int = x
}
object NarrowDependent{
def x: given Int => Int = ???
def y: given (i: Int) => Int = x
}
object WidenDependent{
def x: given (i: Int) => Int = ???
def y: given Int => Int = x
}

0 comments on commit 7db38bf

Please sign in to comment.