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

incorrect handling of insertion into a map with a value of type ListBuffer[AnyRef] #5681

Closed
scabug opened this issue Apr 18, 2012 · 2 comments
Milestone

Comments

@scabug
Copy link

scabug commented Apr 18, 2012

When trying to run the below code you are presented with an error:

error: type arguments [Any] do not conform to trait Cloneable's type parameter bounds [+A <: AnyRef]
              for (param <- andString.split('&')){

========================================================================================================

import scala.collection.mutable.Map
import scala.collection.mutable.ListBuffer

val appleHolder = Map[String,ListBuffer[AnyRef]]()
val andString = "apple=all&apple=123"
for (param <- andString.split('&')){
      val tempSplit = param.split('=')
      appleHolder.get(tempSplit(0)) match{
        case Some(x) => x += tempSplit(1)
        case None => appleHolder += tempSplit(0) -> ListBuffer[AnyRef](tempSplit(1))
      }
}

changing the case for None to the below is a workaround

appleHolder(tempSplit(0)) = ListBuffer[AnyRef](tempSplit(1))
@scabug
Copy link
Author

scabug commented Apr 18, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5681?orig=1
Reporter: rob brazier (rbrazier)
Affected Versions: 2.9.1

@scabug
Copy link
Author

scabug commented May 7, 2012

@heathermiller said:
Fixed in 2.10-M3

Welcome to Scala version 2.10.0-M3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import scala.collection.mutable.Map
import scala.collection.mutable.ListBuffer

val appleHolder = Map[String,ListBuffer[AnyRef]]()
val andString = "apple=all&apple=123"
for (param <- andString.split('&')){
      val tempSplit = param.split('=')
      appleHolder.get(tempSplit(0)) match{
        case Some(x) => x += tempSplit(1)
        case None => appleHolder += tempSplit(0) -> ListBuffer[AnyRef](tempSplit(1))
      }
}


// Exiting paste mode, now interpreting.

import scala.collection.mutable.Map
import scala.collection.mutable.ListBuffer
appleHolder: scala.collection.mutable.Map[String,scala.collection.mutable.ListBuffer[AnyRef]] = Map(apple -> ListBuffer(all, 123))
andString: String = apple=all&apple=123

@scabug scabug closed this as completed May 7, 2012
@scabug scabug added this to the 2.10.0-M3 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant