This does not work because:
token match { case Keywords.ARRAY => println("Array") case _ => println("Something else") }
essentially a PartialFunction with the following type signature: PartialFunction[Keywords.Value, Unit] . This means that the implied will not be applied because it isDefinedAt or not for this input.
If it is not defined than case _ => ... , it will catch everything in my code example. If it is not defined at all and nothing matches it, you will get a MatchError .
In your case, a token type Token[Value] not defined in the Partial function that the match will compile, since only Keywords.Value types are defined.
Three decisions
If you really want implicits, then you can explicitly request implicit (yes, this sentence is ridiculous :))
implicitly[Keywords.Value](token) match { case Keywords.ARRAY => println("Array") case _ => println("Something else") }
Or you can explicitly specify the token type to trigger implicit magic:
val token: Keywords.Value = new Keyword("ARRAY") token match { case Keywords.ARRAY => println("Array") case _ => println("Something else") }
Or the simplest solution if you can live without implication:
token.value match { case Keywords.ARRAY => println("Array") case _ => println("Something else") }
I know that this is not the answer you are looking for, but I hope you understand what match {...} means and what partial functions.
source share