You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scala>List("ab").toSet.head.head
<console>:12:error: value head is not a member of typeparameterBList("ab").toSet.head.head
scala>List("ab").toSet.map(_.length)
res4: scala.collection.immutable.Set[Int] =Set(2)
2.12.6
scala>List("ab").toSet.head.head
<console>:12:error: value head is not a member of typeparameterBList("ab").toSet.head.head
^
scala>List("ab").toSet.map(_.length)
<console>:12:error: missing parameter typefor 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).
scala>List("ab").toSet.head.head
^error: value head is not a member of typeparameterB
scala>List("ab").toSet.map(_.length)
^error: missing parameter typefor 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.
basically scala 2 instantiate type variables as soon as it sees that they have a lower-bound different from Nothing, whereas dotty waits until the last possible moment to do so. this will never be fixed in scala 2.
Activity
scabug commentedon Aug 12, 2013
Imported From: https://issues.scala-lang.org/browse/SI-7743?orig=1
Reporter: Sagie Davidovich (sagie.d)
Affected Versions: 2.10.2
scabug commentedon Aug 12, 2013
Tomer Gabel (holograph) said:
Can be worked around with:
scabug commentedon Aug 12, 2013
@som-snytt said:
scala> List("ab").to[Set].head.head
res1: Char = a
scabug commentedon Aug 12, 2013
Tomer Gabel (holograph) said:
A.P: Which Scala version do you use? In my case:
scabug commentedon Aug 12, 2013
Tomer Gabel (holograph) said:
Also, your code sample is different :-) (toSet -> to[Set])
scabug commentedon Dec 5, 2013
@SethTisue said:
I think this is just another version of this old chestnut: http://stackoverflow.com/questions/5544536/type-inference-on-set-failing
the least intrusive workaround IMO is
List("ab").toSet[String].head.headscabug commentedon Aug 9, 2016
Christopher Vogt (cvogt) said:
Another workaround: {code}List("ab").to[Set].head.head{code}
joroKr21 commentedon Sep 26, 2018
Interesting comparison with typelevel scala:
@milessabin any idea what causes the second example to compile on typelevel scala? Might be worth porting over.
milessabin commentedon Sep 26, 2018
@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?
joroKr21 commentedon Sep 26, 2018
But looking at the tests added in scala/scala@272d17b this appears to be intentional.
milessabin commentedon Sep 26, 2018
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.
adriaanm commentedon Sep 26, 2018
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.
SethTisue commentedon Oct 20, 2020
Hasn't progressed as of 2.13.3, but is fixed in Dotty.
SethTisue commentedon Oct 21, 2020
says @smarter on Gitter:
som-snytt commentedon Nov 14, 2023
Closing as not progressing in Scala 2. Leaving it open is not documentary, but it ought to be a FAQ.