Scala Programming Language
  1. Scala Programming Language
  2. SI-4938

Failure to unify types of mutable collections

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
    • Environment:

      Scala 2.9.1.RC3

      Description

      Entering the following in the REPL,

      if (true) {
        null.asInstanceOf[collection.mutable.Seq[Int]]
      } else {
        null.asInstanceOf[collection.mutable.Set[Int]]
      }
      

      will fail to compile with the error

      <console>:10: error: type arguments [Any] do not conform to trait Cloneable's type parameter bounds [+A <: AnyRef]
             val res0 =
                 ^
      

      I would expect that some valid upper bound should be found. There is no problem with the immutable collection types, nor a combination of immutable and mutable collections.

      The issue was reported on Stack Overflow: http://stackoverflow.com/questions/7155066/adding-to-scala-map-within-for-loop-and-conditional-statement

        Activity

        Hide
        Paul Phillips added a comment -

        For my reference, this is another example of inferred types not conforming to bounds.
        Note the "with scala.collection.mutable.Cloneable[Any]" despite Cloneable's AnyRef bound.

        scala> lub(List("Set", "Seq") map (intp types "scala.collection.mutable." + _) map (s => typeRef(NoPrefix, s, List(ObjectClass.tpe))))
        
        res22: $r.intp.global.Type = 
          scala.collection.mutable.Iterable[java.lang.Object] 
          with java.lang.Object 
          with Int => Any 
          with scala.collection.mutable.Cloneable[
            scala.collection.mutable.Iterable[java.lang.Object] 
            with java.lang.Object 
            with Int => Any 
            with scala.collection.mutable.Cloneable[
              scala.collection.mutable.Iterable[java.lang.Object] 
              with java.lang.Object 
              with Int => Any 
              with scala.collection.mutable.Cloneable[
                scala.collection.mutable.Iterable[java.lang.Object] 
                with Nothing => Any 
                with scala.collection.mutable.Cloneable[Any]
              ] {
                def seq:  scala.collection.mutable.Iterable[java.lang.Object] 
                            with Nothing => Any 
                            with scala.collection.mutable.Cloneable[Any]
                }
            ]
          ]
        
        Show
        Paul Phillips added a comment - For my reference, this is another example of inferred types not conforming to bounds. Note the "with scala.collection.mutable.Cloneable [Any] " despite Cloneable's AnyRef bound. scala> lub(List("Set", "Seq") map (intp types "scala.collection.mutable." + _) map (s => typeRef(NoPrefix, s, List(ObjectClass.tpe)))) res22: $r.intp.global.Type = scala.collection.mutable.Iterable[java.lang.Object] with java.lang.Object with Int => Any with scala.collection.mutable.Cloneable[ scala.collection.mutable.Iterable[java.lang.Object] with java.lang.Object with Int => Any with scala.collection.mutable.Cloneable[ scala.collection.mutable.Iterable[java.lang.Object] with java.lang.Object with Int => Any with scala.collection.mutable.Cloneable[ scala.collection.mutable.Iterable[java.lang.Object] with Nothing => Any with scala.collection.mutable.Cloneable[Any] ] { def seq: scala.collection.mutable.Iterable[java.lang.Object] with Nothing => Any with scala.collection.mutable.Cloneable[Any] } ] ]
        Hide
        Paul Phillips added a comment -

        Assigning to meeting because I know how to fix it and I hate to not do so on the basis that I can't address every imaginable case.

        Show
        Paul Phillips added a comment - Assigning to meeting because I know how to fix it and I hate to not do so on the basis that I can't address every imaginable case.
        Hide
        Paul Phillips added a comment -

        Going to use my lub ninja touch to fix this without breaking anything else.

        Show
        Paul Phillips added a comment - Going to use my lub ninja touch to fix this without breaking anything else.
        Hide
        Commit Message Bot added a comment -

        (extempore in r25650) Refine lub calculation.

        When a reasonable lub cannot be arrived at by direct means,
        use the bounds of the lub inputs to derive bounds for the lub
        rather than giving up. Closes SI-4938, review by moors.

        Show
        Commit Message Bot added a comment - (extempore in r25650 ) Refine lub calculation. When a reasonable lub cannot be arrived at by direct means, use the bounds of the lub inputs to derive bounds for the lub rather than giving up. Closes SI-4938 , review by moors.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Kipton Barros
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development