We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The following code can be compiled with no errors by 2.10.0
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_32). Type in expressions to have them evaluated. Type :help for more information. scala> def packAny(value: Any) { | value match { | case x: collection.GenMapLike[_,_,_] => | for((k,v) <- x) { ??? } | } | } packAny: (value: Any)Unit
But cannot be compiled by 2.10.1 and 2.10.2
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_32). Type in expressions to have them evaluated. Type :help for more information. scala> def packAny(value: Any) { | value match { | case x: collection.GenMapLike[_,_,_] => | for((k,v) <- x) { ??? } | } | } <console>:10: error: value foreach is not a member of _ for((k,v) <- x) { ??? } ^
The text was updated successfully, but these errors were encountered:
Imported From: https://issues.scala-lang.org/browse/SI-7667?orig=1 Reporter: Denis Petrov (denis) Affected Versions: 2.10.1 See #6968
Sorry, something went wrong.
@retronym said: This is basically a duplicate of #7222.
In 2.10.0, the parser phase of the compiler desugared your for-comprehension as irrefutable, ie to x.foreach { case (k, v) => }.
x.foreach { case (k, v) => }
However, it can't do that in general for tuple patterns; they are supposed to parse to a withFilter call. That's important for code like:
withFilter
for ( (a, b) <- List[Any]((1, 2), "boo"))
That code should return a one element list; if we omit the withFilter we'll get a MatchError instead.
MatchError
So now your example is desugared to:
x.withFilter { case (k, v) => (k, v) }.foreach(_ => ???)
{withFilter} returns Repr, the third type argument of GenMapLike, which you have bound to an existential type. As such, it doesn't support foreach.
Repr
GenMapLike
foreach
I suggest in this case to call foreach directly:
x foreach { case (k, v) => ??? }
retronym
No branches or pull requests
The following code can be compiled with no errors by 2.10.0
But cannot be compiled by 2.10.1 and 2.10.2
The text was updated successfully, but these errors were encountered: