I apologize if this is the wrong category to post in. The Scala bug reporting guide ( https://www.scala-lang.org/contribute/bug-reporting-guide.html ) suggested this category, but the category description doesn’t mention bugs, so if this isn’t appropriate, I’m sorry.
I found a confusing error in the Scala compiler. Some code that demonstrates the problem:
trait ParamTrait
class ImplementingParamTrait extends ParamTrait
trait Model[P <: ParamTrait] {
def create(conditionalParams: P)(implicit d: Double): Int
}
object Obj extends Model[ImplementingParamTrait] {
def create(conditionalParams: ImplementingParamTrait)(d: Double): Int =
5
}
When trying to compile this (through both sbt and scalac), I get the following error:
src/main/scala/ErrorMessageExample.scala:9: error: object creation impossible, since method create in trait Model of type (conditionalParams: ImplementingParamTrait)(implicit d: Double)Int is not defined
(Note that P does not match ImplementingParamTrait)
object Obj extends Model[ImplementingParamTrait] {
^
one error found
Now, the error in the code seems to be that there is no implicit
keyword in the second set of params for the create
method definition in Obj
. If you change it to read
def create(conditionalParams: ImplementingParamTrait)(implicit d: Double): Int = 5
then it compiles without a problem.
However, I was curious why the compiler includes the message Note that P does not match ImplementingParamTrait
in the error message. For one, it doesn’t seem to have anything to do with the actual problem, and secondly, as far as I can tell, inside Obj
, P
should be ImplementingParamTrait
.
Can someone help me understand the error message? Or, if this is a bad error message, can someone direct me as to where to file a bug request?