Skip to content

Fix #5833: Refine condition what constitutes an IFT in adapt #5841

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 1 commit into from
Feb 6, 2019
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
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
}