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
List("ab").toSet.head.head won't compile #7743
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7743?orig=1 |
Tomer Gabel (holograph) said: scala> val a=List("ab").toSet.head
a: String = ab
scala> a.head
res2: Char = a |
@som-snytt said: |
Tomer Gabel (holograph) said: arilou:incubator-curator tomer$ scala -version
Scala code runner version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL |
Tomer Gabel (holograph) said: |
@SethTisue said: the least intrusive workaround IMO is |
Christopher Vogt (cvogt) said: |
Interesting comparison with typelevel scala:
scala> List("ab").toSet.head.head
<console>:12: error: value head is not a member of type parameter B
List("ab").toSet.head.head
scala> List("ab").toSet.map(_.length)
res4: scala.collection.immutable.Set[Int] = Set(2)
scala> List("ab").toSet.head.head
<console>:12: error: value head is not a member of type parameter B
List("ab").toSet.head.head
^
scala> List("ab").toSet.map(_.length)
<console>:12: error: missing parameter type for expanded function ((x$1: <error>) => x$1.length)
List("ab").toSet.map(_.length) @milessabin any idea what causes the second example to compile on typelevel scala? Might be worth porting over. |
@joroKr21 I'm pretty sure it's down to some experimental bounds propagation work that @paulp did (scala/scala@dc1bbb9) which turned out to be important to the literal types PR. I'm not quite sure where it ended up. I rolled it into the the unconditionalizing of literal types (scala/scala@beb2dac), then it might have been removed, or at least simplified by @adriaanm (scala/scala@272d17b). How does it look in 2.13.0-M5? |
scala> List("ab").toSet.head.head
^
error: value head is not a member of type parameter B
scala> List("ab").toSet.map(_.length)
^
error: missing parameter type for expanded function ((x$1: <error>) => x$1.length) But looking at the tests added in scala/scala@272d17b this appears to be intentional. |
I think the tests might be documenting the status quo, however. It would be good to know what breakage was actually motivating sticking with that. @adriaanm? It might be worth reviving this as a separate PR. I'd certainly consider it for the next TLS releases. |
There's a second test to illustrate the problem with adding the bounds from the start. You end up over-constraining the type variable. Sometimes it's important that we know it's undetermined (by the environment), so that we use Wildcard as the expected type, rather than the bound that's on the type parameter. Typing without expected type may result in a sharper type than typing under, say, AnyVal. |
Hasn't progressed as of 2.13.3, but is fixed in Dotty. |
says @smarter on Gitter:
|
Closing as not progressing in Scala 2. Leaving it open is not documentary, but it ought to be a FAQ. |
The text was updated successfully, but these errors were encountered: