Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top