Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala 2.8 handles Boolean and java.lang.Boolean properly?

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.

like image 718
Jus12 Avatar asked Oct 16 '11 09:10

Jus12


2 Answers

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.

like image 53
huynhjl Avatar answered Sep 23 '22 04:09

huynhjl


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.

like image 23
psp Avatar answered Sep 24 '22 04:09

psp