diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 2 | ||||
-rw-r--r-- | test/files/neg/t9953.check | 6 | ||||
-rw-r--r-- | test/files/neg/t9953.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t9953.scala | 13 |
4 files changed, 21 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 106b076eef..34cdfcdd39 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1103,7 +1103,7 @@ abstract class RefChecks extends Transform { // better to have lubbed and lost def warnIfLubless(): Unit = { val common = global.lub(List(actual.tpe, receiver.tpe)) - if (ObjectTpe <:< common && !(ObjectTpe <:< actual.tpe && ObjectTpe <:< receiver.tpe)) + if (ObjectTpe <:< common && !(ObjectTpe <:< actual.tpe) && !(ObjectTpe <:< receiver.tpe)) unrelatedTypes() } // warn if actual has a case parent that is not same as receiver's; diff --git a/test/files/neg/t9953.check b/test/files/neg/t9953.check new file mode 100644 index 0000000000..f5dcbcacee --- /dev/null +++ b/test/files/neg/t9953.check @@ -0,0 +1,6 @@ +t9953.scala:10: warning: Object and X are unrelated: they will never compare equal + def b = y == x // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/test/files/neg/t9953.flags b/test/files/neg/t9953.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/neg/t9953.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/neg/t9953.scala b/test/files/neg/t9953.scala new file mode 100644 index 0000000000..faaee86d50 --- /dev/null +++ b/test/files/neg/t9953.scala @@ -0,0 +1,13 @@ + +class X(val v: Int) extends AnyVal +trait T extends Any +object Y extends T + +class C { + val x = new X(42) + val y = new Object + val a: T = null + def b = y == x // warn + def c = y == a // no warn + def d = Y == a // no warn +} |