question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scala 2 regression: F-bounds + wildcard

See original GitHub issue

Compiler version

  • 3.0.0
  • 3.0.1
  • 3.0.2-RC1

Minimized code

object Blah {
  trait DomZipper[F[_], X, A, Self[G[_], B] <: DomZipper[G, X, B, Self]]
  def apply[Fast[f[_], a] <: DomZipper[f, _, a, Fast]] = () // error
}

object Blah1 {
  trait DomZipper[X, A, Self[B] <: DomZipper[X, B, Self]]
  def apply[Fast[a] <: DomZipper[_, a, Fast]] = () // error
}

object Blah2 {
  trait DomZipper[F[_], X, Self[G[_]] <: DomZipper[G, X, Self]]
  def apply[Fast[f[_]] <: DomZipper[f, _, Fast]] = () // error
  
  def apply1[Fast[f[_]] <: DomZipper[f, _, Fast]] = () // error
}

object Blah3 {
  trait DomZipper[F[_], Self[G[_]] <: DomZipper[G, Self]]
  def apply[Fast[f[_]] <: DomZipper[f, Fast]] = () // ok
}

object Blah4 {
  trait DomZipper[Self <: DomZipper[Self]]
  def apply[Fast <: DomZipper[Fast]] = () // ok
}

object Blah5 {
  trait DomZipper[F[_], A, Self[G[_], B] <: DomZipper[G, B, Self]]
  def apply[Fast[f[_], a] <: DomZipper[f, a, Fast]] = () // ok
}

object Blah6 {
  trait DomZipper[F[_], X, A, Self[G[_], B] <: DomZipper[G, X, B, Self]]
  def apply[Fast[f[_], a] <: DomZipper[f, X, a, Fast], X] = () // ok
}

Output

[error] -- [E057] Type Mismatch Error: a.scala:3:48 
[error] 3 |  def apply[Fast[f[_], a] <: DomZipper[f, _, a, Fast]] = () // error
[error]   |                                                ^
[error]   |Type argument Fast does not conform to upper bound [G[_$2], B] =>> Blah.DomZipper[G, Blah.DomZipper[f, ?, a, Fast]#X, B, Fast]
[error] -- [E057] Type Mismatch Error: a.scala:8:39 
[error] 8 |  def apply[Fast[a] <: DomZipper[_, a, Fast]] = () // error
[error]   |                                       ^
[error]   |Type argument Fast does not conform to upper bound [B] =>> Blah1.DomZipper[Blah1.DomZipper[?, a, Fast]#X, B, Fast]
[error] -- [E057] Type Mismatch Error: a.scala:13:42 
[error] 13 |  def apply[Fast[f[_]] <: DomZipper[f, _, Fast]] = () // error
[error]    |                                          ^
[error]    |Type argument Fast does not conform to upper bound [G[_$5]] =>> Blah2.DomZipper[G, Blah2.DomZipper[f, ?, Fast]#X, Fast]
[error] -- [E057] Type Mismatch Error: a.scala:15:43 
[error] 15 |  def apply1[Fast[f[_]] <: DomZipper[f, _, Fast]] = () // error
[error]    |                                           ^
[error]    |Type argument Fast does not conform to upper bound [G[_$5]] =>> Blah2.DomZipper[G, Blah2.DomZipper[f, ?, Fast]#X, Fast]
[error] four errors found

Expectation

Compiles with Scala 2.12 and 2.13.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
smartercommented, Jul 23, 2021

Not going to fix all the f-bounds issues sorry 😃.

1reaction
oderskycommented, Aug 1, 2021

It’s a missing capture conversion. The error message is

trait DomZipper[X, A, Self[B] <: DomZipper[X, B, Self]]
def apply[Fast[a] <: DomZipper[_, a, Fast]] = () // error
                                     ^
  Type argument Fast does not conform to upper bound [B] =>> DomZipper[DomZipper[?, a, Fast]#X, B, Fast]

Essentially it needs to argue that for each version of Fast there is one specific first argument of X. I am not even sure this is true. Scala 2 handles these wildcards differently and in ways where we know that there are soundness problems. The example is too complex for me to figure out whether this should be sound or not. So I don’t think I can help here. If someone else wants to step in, please re-open as needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regression in Scala 2.13.7 - cannot use wildcard for F- ...
Regression in Scala 2.13.7 - cannot use wildcard for F-bounded type ... [_$2] do not conform to trait Universe's type parameter bounds [T ......
Read more >
Scala 3.0.1-RC2 – backports of critical bugfixes - EPFL
1. The reason for this release is that a regression with respect to 3.0.0 was introduced by PR #12519 which caused the compiler...
Read more >
Generics and Wildcards in Java - Level Up Coding
This is as flexible as the Java method with type bounds because, in Scala, List is covariant and functions are covariant in their...
Read more >
Scala list of any and list of something extending ...
2. Any is a symptom of bad design · 1. @user You can. · 1. @cchantep Generally yes, but for covariant F ,...
Read more >
A Beginner's Guide to Scala, Object Orientation and ...
2. 1.4 Java to Scala Quick Comparison . ... 28.5 Lower and Upper Bounds. ... Also note that if you are a Java...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found