Skip to content

Commit 482de4e

Browse files
author
Aggelos Biboudis
authored
Merge pull request #5841 from dotty-staging/fix-#5833
Fix #5833: Refine condition what constitutes an IFT in adapt
2 parents 788b4fa + c20730a commit 482de4e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,9 +2561,17 @@ class Typer extends Namer
25612561
missingArgs(wtp)
25622562
}
25632563

2564+
def isImplicitFunctionRef(wtp: Type): Boolean = wtp match {
2565+
case RefinedType(parent, nme.apply, _) =>
2566+
isImplicitFunctionRef(parent) // apply refinements indicate a dependent IFT
2567+
case _ =>
2568+
val underlying = wtp.underlyingClassRef(refinementOK = false) // other refinements are not OK
2569+
defn.isImplicitFunctionClass(underlying.classSymbol)
2570+
}
2571+
25642572
def adaptNoArgsOther(wtp: Type): Tree = {
25652573
ctx.typeComparer.GADTused = false
2566-
if (defn.isImplicitFunctionClass(wtp.underlyingClassRef(refinementOK = false).classSymbol) &&
2574+
if (isImplicitFunctionRef(wtp) &&
25672575
!untpd.isContextualClosure(tree) &&
25682576
!isApplyProto(pt) &&
25692577
!ctx.mode.is(Mode.Pattern) &&

tests/pos/i5833.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Dependent{
2+
def x: given (i: Int) => Int = ???
3+
def y: given (i: Int) => Int = x
4+
}
5+
object Independent{
6+
def x: given Int => Int = ???
7+
def y: given Int => Int = x
8+
}
9+
object NarrowDependent{
10+
def x: given Int => Int = ???
11+
def y: given (i: Int) => Int = x
12+
}
13+
object WidenDependent{
14+
def x: given (i: Int) => Int = ???
15+
def y: given Int => Int = x
16+
}

0 commit comments

Comments
 (0)