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

Failure to unify types of mutable collections #4938

Closed
scabug opened this issue Aug 23, 2011 · 5 comments
Closed

Failure to unify types of mutable collections #4938

scabug opened this issue Aug 23, 2011 · 5 comments
Assignees
Labels
lub

Comments

@scabug
Copy link

@scabug scabug commented Aug 23, 2011

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 23, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4938?orig=1
Reporter: Kipton Barros (kbarros)

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 23, 2011

@paulp said:
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]
        }
    ]
  ]
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 6, 2011

@paulp said:
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 6, 2011

@paulp said:
Going to use my lub ninja touch to fix this without breaking anything else.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 13, 2011

Commit Message Bot (anonymous) said:
(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 #4938, review by moors.

@scabug scabug closed this Sep 13, 2011
@scabug scabug added the lub label Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.