Juh_ Juh_ - 3 months ago 10
Scala Question

How not to require the import of scala.language.relectiveCalls

I subclassed

org.scalatest.FlatSpec
to add practical tooling to FlatTest. But anywhere I use this subclass, I have to import
scala.language.reflectiveClass
otherwise I get

reflective access of structural type member method test should be enabled
by making the implicit value scala.language.reflectiveCalls visible.


The method
test
in question is the equivalent to
should
in standard FlatSpec:

it should "do some stuff" in { ...}


Why is it not necessary to import reflectiveCalls to use flatSpec
should
but is necessary for my
test
method, and how can I avoid that?

Answer

The reason why you are getting this warning is that you have structural type reference or new {...} call somewhere in your test method.

Unfortunately there is no way to turn off that warning other than by explicit scala.language.reflectiveClass import or rewriting your code.