From 92feee6a6e45c444b2ebdc3d8b574b7e30d0f36e Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sun, 25 Mar 2018 21:00:13 +0200 Subject: [PATCH] Fix #4180: Can't compare Scala and Java Booleans --- library/src/scala/Eq.scala | 5 ++++- tests/neg/equality.scala | 4 ++-- tests/pos/i4180.scala | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i4180.scala diff --git a/library/src/scala/Eq.scala b/library/src/scala/Eq.scala index 1e443e76f7db..15869024d003 100644 --- a/library/src/scala/Eq.scala +++ b/library/src/scala/Eq.scala @@ -55,4 +55,7 @@ object Eq extends Eq[Any, Any] { implicit def eqNumFloat : Eq[Number, Float] = Eq implicit def eqDoubleNum: Eq[Double, Number] = Eq implicit def eqNumDouble: Eq[Number, Double] = Eq -} \ No newline at end of file + + implicit def eqSBoolJBool: Eq[Boolean, java.lang.Boolean] = Eq + implicit def eqJBoolSBool: Eq[java.lang.Boolean, Boolean] = Eq +} diff --git a/tests/neg/equality.scala b/tests/neg/equality.scala index e4042e9a7266..595d1de6564f 100644 --- a/tests/neg/equality.scala +++ b/tests/neg/equality.scala @@ -58,8 +58,8 @@ object equality { 1 == true // error - null == true // OK by eqProxy - true == null // error + null == true // OK by eqProxy or eqJBoolSBool + true == null // OK by eqSBoolJBool null == 1 // OK by eqProxy or eqNumInt 1 == null // OK by eqIntNum diff --git a/tests/pos/i4180.scala b/tests/pos/i4180.scala new file mode 100644 index 000000000000..df0e49b262ef --- /dev/null +++ b/tests/pos/i4180.scala @@ -0,0 +1,6 @@ +object Test { + def foo(s: Boolean, j: java.lang.Boolean) = { + val a = s == j + val b = j == s + } +}