coltfred
coltfred

Reputation: 1480

Why is partially applying functions on an implicit class giving me an error?

object RegexImplicits{
  implicit class RegexWrapper(r: scala.util.matching.Regex) {
    def matches(s: CharSequence): Boolean = r.pattern.matcher(s).find
  }

  def something(s:String):Boolean = s == "42"
}
import RegexImplicits._

//This errors with the message
//<console>:16: error: missing arguments for method matches in class RegexWrapper;
//follow this method with `_' if you want to treat it as a partially applied function
//              "a".r.matches _ 
"a".r.matches _ 

//But this works fine...
something _

Why does something _ work but the value involving the implicit class does not?

Does this have to do with the implicit class or is that a red herring and I'm experiencing a different problem?

Upvotes: 2

Views: 117

Answers (1)

coltfred
coltfred

Reputation: 1480

It turns out as om-nom-nom pointed out, this is a known bug in the scala compiler.

http://issues.scala-lang.org/browse/SI-3218

Paulp's recommendations are to either use the dot free form or surround the _ with parentheses.

"a".r matches _

or

"a".r.matches(_)

Upvotes: 3

Related Questions