I have a code which uses pimped jme Quaternion math. The math extension (for Java jMonkeyEngine Quaternion) looks like this:
object Operators {
implicit class QuaternionMath(val a: Quaternion) extends AnyVal {
def * (b: Quaternion) = a mult b
//def * (b: Float) = a mult b
}
}
The code using the math looks like this:
import Operators._
... and later in a function:
def compute(q1: Quaternion, q2: Quaternion) = {
q1 * q2
}
Now after adding some more code which seems not related, I get a syntax error:
Error:(477, 10) value * is not a member of com.jme3.math.Quaternion
To fix the error I need to repeat the import right before the computation, either as a wildcard again, or a specific one:
import Operators.QuaternionMath
import Operators._
I have no idea what can be hiding the QuaternionMath implicit conversion. Is there some way how to check that, some tool, or some compiler switches?
If QuaternionMath really is in scope, you should be able to write
val m: location.of.Operators.QuaternionMath = QuaternionMath(q1)
m.*(c2)
If the first line fails, it will be telling either that
QuaternionMath is not found. It's really not in scopeQuaternionMath. In this case you could in an IDE just jump to the source of that shadowing symbol.QuaternionMath is not a member of Operators (my guess here). Then Operators is not that object that you imagine but another one with the same name. Again in the IDE, just select the Operators bit of import Operators._ and look up the source (Ctrl-B in IntelliJ) to verify you are doing what you think you are doing.If you are using IntelliJ IDEA for Scala then try checking possible implicit conversions by selecting an expression and pressing ctrl+shift+q (ctrl+q for Mac), check this tutorial.
For Scala IDE there is implicit conversion highlighting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With