lundi 10 juin 2019

Why does this type equality check fail in SBT but succeed in my IDE?

I encountered an interesting issue while writing unit tests, a particular piece of type checking Scala code succeeding when I run the tests through my IDE (IntelliJ Idea), while failing when I ran them through SBT with sbt test. The code in question is simply this line:

tag == typeTag[Unit]

with tag here being a TypeTag[A]. So the check is determining through reflection if a parametric type is a Unit, nothing more. I'm aware the equality check is flawed and I should use Scala's reflection API operators, I have already rewritten it as such and it now passes the tests through both my IDE and SBT:

tag.tpe =:= typeOf[Unit]

My question is not how to fix my problem (since I already have), but rather why the flawed check would always succeed when run through my IDE but always fail when run through SBT, what is different between these two operations that would cause this disparity?

(Some versioning info: I'm using JRE 11.0.2, Scala 2.12 and SBT 1.2.8 in my code)





Aucun commentaire:

Enregistrer un commentaire