Scala 2.8 handles Boolean and java.lang.Boolean properly?
Asked Answered
L

2

8

Consider the following:

scala> val a:java.lang.Boolean = true
a: java.lang.Boolean = true

scala> val b = true
b: Boolean = true

scala> a == b
res4: Boolean = true

scala> b == a
<console>:8: warning: comparing values of types Boolean 
and java.lang.Boolean using `==' will always yield false
       b == a
         ^
res5: Boolean = true

The warning says that it will yield false but it yields true.

Scala 2.8.

Lowermost answered 16/10, 2011 at 9:40 Comment(2)
Will probably not help you much but scala 2.9.1 behaves as expected. (no warning)Retrogression
+1 for lols. Is fixed in 2.9.0 as well. I think you can ignore this warning.Anchorage
E
3

A bit of source code control archaeology shows that handling of those warnings were improved after 2.8.1. Here is the annotated revisions to the unit tests for those warnings.

https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/test/files/neg/checksensible.scala?annotate=blame&rev=25638

This is compared to rev 19169 in 2.8.1 final that is a lot more basic:

https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/test/files/neg/checksensible.scala

I think this gives a sense that more attention was provided to this after 2.8.1.

Looking at some bug reports, it seems the warning are really just that - hopefully helping identify errors. If you know what you're doing (such as comparing java Boolean and scala Boolean), then you can ignore.

Egret answered 16/10, 2011 at 23:55 Comment(0)
C
1

Interestingly, this has regressed. In recent warning enhancements I must be excluding numerics and missing boolean. The error message in trunk for comparing java.lang.Boolean and Boolean is impressively confusing.

Claudy answered 18/10, 2011 at 15:14 Comment(1)
Oops, meant that as a comment to huynhjl's answer.Claudy

© 2022 - 2024 — McMap. All rights reserved.