type safe matchers?

77 views
Skip to first unread message

Kostas kougios

unread,
Mar 9, 2015, 12:58:47 PM3/9/15
to scalate...@googlegroups.com
Hi, I am occasionally bumping into this problem where I my code returns say a Map() but I incorrectly "should be (List...)"

Obviously this will always fail and in my opinion it shouldn't compile.

I assume there is a reason for matchers not been type safe, but are there any type safe matchers I can use?

Thanks

Bill Venners

unread,
Mar 9, 2015, 2:34:45 PM3/9/15
to scalate...@googlegroups.com
Hi Kostas,

We did implement type checks for equal, be, and contain matchers and
this works in master on github, but the problem currently is I'm
worried about the compile time impact. We will be measuring that this
week more carefully, to isolate that difference from other differences
(we've added other things into master).

scala> import org.scalactic._
import org.scalactic._

scala> import org.scalatest._
import org.scalatest._

scala> import Matchers._
import Matchers._

scala> import CheckedEquality._
import CheckedEquality._

scala> Map("one" -> 1, "two" -> 2) should be (List(1, 2, 3))
<console>:32: error: Could not find evidence that
scala.collection.immutable.Map[String,Int] can equal List[Int]; the
missing implicit parameter is of type
org.scalactic.EqualityConstraint[scala.collection.immutable.Map[String,Int],List[Int]]
Map("one" -> 1, "two" -> 2) should be (List(1, 2, 3))
^

So it works, but if I can't get the compile time to be near what it
was before, I may have to go back to the drawing board.

Bill
> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
> ---
> You received this message because you are subscribed to the Google Groups
> "scalatest-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalatest-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Bill Venners
Artima, Inc.
http://www.artima.com

Konstantinos Kougios

unread,
Mar 10, 2015, 8:36:58 AM3/10/15
to scalate...@googlegroups.com
Hi Bill,

Why compilation time is higher? More implicits?

P.S. I think I've managed to chop off 5 secs of my 58 secs compilation
for my project by importing Matchers._ instead of mixing it in.

Bill Venners

unread,
Mar 10, 2015, 11:30:01 AM3/10/15
to scalate...@googlegroups.com
Hi Konstantinos,

On Tue, Mar 10, 2015 at 5:36 AM, Konstantinos Kougios
<kostas....@googlemail.com> wrote:
> Hi Bill,
>
> Why compilation time is higher? More implicits?
>
More implicit lookups and more overloaded methods.

> P.S. I think I've managed to chop off 5 secs of my 58 secs compilation for
> my project by importing Matchers._ instead of mixing it in.
>
Yes, imports compile marginally faster than mixins, because the
compiler doesn't need to insert methods, but you can also make base
classes for your project. Mixin once to your base classes then use
that everywhere also will get you a similar speed boost.

Bill
Reply all
Reply to author
Forward
0 new messages