javadba javadba - 2 months ago 6
Scala Question

Error: value r is not a member of String for a simple regex

For the following straightforward regex that works fine in the

repl
:

val tsecs = """[^\d]+([\d]+)*""".r
tsecs: scala.util.matching.Regex = [^\d]+([\d]+)*


Why would it not compile - either in Intellij or on the commandline via
mvn compile
?

val tsecs = """[^\d]+([\d]+)*""".r

error: value r is not a member of String
[ERROR] val tsecs = """[^\d]+([\d]+)*""".r


The version is scala 2.10.5 in all cases.

Answer

There are a few ways to disable Predef.

import scala.Predef.{wrapString => _, augmentString => _,  _}

object Test extends App {
  def r = "x".r
}

Or

object Test extends App {
  val wrapString, augmentString = 42
  def r = "x".r
}

Or compile with -Yno-imports.

Comments