Skip to content

Commit f23deba

Browse files
committed
address review comments
1 parent 45e188c commit f23deba

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ trait Implicits:
10421042
* - if one of T, U is a subtype of the lifted version of the other,
10431043
* unless strict equality is set.
10441044
*/
1045-
def assumedCanEqual(leftTreeOption: Option[Tree], ltp: Type, rtp: Type)(using Context): Boolean = {
1045+
def assumedCanEqual(ltp: Type, rtp: Type, leftTree: Tree = EmptyTree)(using Context): Boolean = {
10461046
// Map all non-opaque abstract types to their upper bound.
10471047
// This is done to check whether such types might plausibly be comparable to each other.
10481048
val lift = new TypeMap {
@@ -1067,16 +1067,15 @@ trait Implicits:
10671067
|| rtp.isError
10681068
|| locally:
10691069
if strictEquality then
1070-
strictEqualityPatternMatching && leftTreeOption.exists: leftTree =>
1071-
ltp <:< lift(rtp) && (leftTree.symbol.flags.isAllOf(Flags.EnumValue) || leftTree.symbol.flags.isAllOf(Flags.Module | Flags.Case))
1070+
strictEqualityPatternMatching && (leftTree.symbol.isAllOf(Flags.EnumValue) || leftTree.symbol.isAllOf(Flags.Module | Flags.Case)) && ltp <:< lift(rtp)
10721071
else
1073-
(ltp <:< lift(rtp) || rtp <:< lift(ltp))
1072+
ltp <:< lift(rtp) || rtp <:< lift(ltp)
10741073
}
10751074

1076-
/** Check that equality tests between types `ltp` and `rtp` make sense */
1075+
/** Check that equality tests between types `ltp` and `left.tpe` make sense */
10771076
def checkCanEqual(left: Tree, rtp: Type, span: Span)(using Context): Unit =
10781077
val ltp = left.tpe.widen
1079-
if !ctx.isAfterTyper && !assumedCanEqual(Some(left), ltp, rtp) then
1078+
if !ctx.isAfterTyper && !assumedCanEqual(ltp, rtp, left) then
10801079
val res = implicitArgTree(defn.CanEqualClass.typeRef.appliedTo(ltp, rtp), span)
10811080
implicits.println(i"CanEqual witness found for $ltp / $rtp: $res: ${res.tpe}")
10821081

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
183183
* one of `tp1`, `tp2` has a reflexive `CanEqual` instance.
184184
*/
185185
def validEqAnyArgs(tp1: Type, tp2: Type)(using Context) =
186-
typer.assumedCanEqual(None, tp1, tp2)
186+
typer.assumedCanEqual(tp1, tp2)
187187
|| withMode(Mode.StrictEquality) {
188188
!hasEq(tp1) && !hasEq(tp2)
189189
}

0 commit comments

Comments
 (0)