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

Stream #:: and #::: don't allow type widening #9886

Closed
scabug opened this issue Aug 11, 2016 · 4 comments
Closed

Stream #:: and #::: don't allow type widening #9886

scabug opened this issue Aug 11, 2016 · 4 comments

Comments

@scabug
Copy link

scabug commented Aug 11, 2016

This seems like a simple oversight where the methods were defined without a [B >: A] type parameter.

These don't work:

scala> None #:: Stream(Some(1))
<console>:12: error: type mismatch;
 found   : None.type
 required: Some[Int]
       None #:: Stream(Some(1))
            ^

scala> Stream(None) #::: Stream(Some(1))
<console>:12: error: type mismatch;
 found   : scala.collection.immutable.Stream[None.type]
 required: scala.collection.immutable.Stream[Some[Int]]
       Stream(None) #::: Stream(Some(1))
                    ^

but surely they should given that List :: and ::: allow it:

scala> None :: List(Some(1))
res2: List[Option[Int]] = List(None, Some(1))

scala> List(None) ::: List(Some(1))
res4: List[Option[Int]] = List(None, Some(1))

And given that other Stream operations allow widening:

scala> Stream.cons(None, Stream(Some(1)))
res10: Stream.Cons[Option[Int]] = Stream(None, ?)

scala> Stream(None).append(Stream(Some(1)))
res12: scala.collection.immutable.Stream[Option[Int]] = Stream(None, ?)

scala> Stream(None) ++ Stream(Some(1))
res13: scala.collection.immutable.Stream[Option[Int]] = Stream(None, ?)
@scabug
Copy link
Author

scabug commented Aug 11, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9886?orig=1
Reporter: @SethTisue
Affected Versions: 2.11.8, 2.12.0-M5

@scabug
Copy link
Author

scabug commented Nov 12, 2016

@ruippeixotog said:
scala/scala#5522

@catalin-ursachi
Copy link

Has this ticket been fixed by scala/scala#5522?

@ruippeixotog
Copy link
Member

Yes, it was fixed with scala/scala#5522:

Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_152).
Type in expressions for evaluation. Or try :help.

scala> None #:: Stream(Some(1))
res0: scala.collection.immutable.Stream[Option[Int]] = Stream(None, ?)

scala> Stream(None) #::: Stream(Some(1))
res1: scala.collection.immutable.Stream[Option[Int]] = Stream(None, ?)

Thanks for noticing that this was still open, I'll close this now.

@SethTisue SethTisue modified the milestones: Backlog, 2.12.4, 2.12.2 Oct 25, 2017
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

4 participants