Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expression match is not working #7210

Closed
scabug opened this issue Mar 3, 2013 · 3 comments
Closed

Regular expression match is not working #7210

scabug opened this issue Mar 3, 2013 · 3 comments

Comments

@scabug
Copy link

scabug commented Mar 3, 2013

The code snippet below print "Boo" 4 times which is wrong, it should only print 3 Boo and a 'Go New York'.

    val matchNY = "^.*New.*$".r

    val teams = List(
        "Toronto Raptor",
        "New York Nets",
        "San Francisco 49ers",
        "Dallas Mavericks"
    )

    for (team <- teams) {
        team match {
            case `matchNY` => println("Go New York.")
            case _ => println("Boo")
        }
    }
@scabug
Copy link
Author

scabug commented Mar 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7210?orig=1
Reporter: David Chang (davidchang168)
Affected Versions: 2.10.0
See #7211

@scabug
Copy link
Author

scabug commented Mar 3, 2013

@retronym said:
You are checking if "Toronto Raptor" == matchNY.

Please address follow-up questions to [scala-user] or StackOverflow, and reserve the bug tracker for issues where you've double checked the behaviour on such a forum.

@scabug scabug closed this as completed Mar 3, 2013
@scabug
Copy link
Author

scabug commented Mar 3, 2013

@retronym said:
I've opened #7211 to issue a warning in this case; the compiler knows that a String can't be equal to a Regex, either because a) String is final and doesn't inherit Regex, or b) both are classes, and other classes can only inherit one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant