Skip to content

Commit 60d59ee

Browse files
committed
Merge pull request scala#4102 from retronym/ticket/8965
SI-8965 Account for corner case in "unrelated types" warning
2 parents 5a7875f + b8f7fbe commit 60d59ee

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
10951095
// better to have lubbed and lost
10961096
def warnIfLubless(): Unit = {
10971097
val common = global.lub(List(actual.tpe, receiver.tpe))
1098-
if (ObjectTpe <:< common)
1098+
if (ObjectTpe <:< common && !(ObjectTpe <:< actual.tpe && ObjectTpe <:< receiver.tpe))
10991099
unrelatedTypes()
11001100
}
11011101
// warn if actual has a case parent that is not same as receiver's;

test/files/pos/t8965.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xfatal-warnings

test/files/pos/t8965.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
def f(x: Any with AnyRef, y: Any with AnyRef) = x eq y
3+
// a.scala:2: warning: Any and Any are unrelated: they will most likely never compare equal
4+
// def f(x: Any with AnyRef, y: Any with AnyRef) = x eq y
5+
// ^
6+
// one warning found
7+
}

0 commit comments

Comments
 (0)