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

Regression in mjakubowski84/parquet4s for type inference #21275

Closed
WojciechMazur opened this issue Jul 25, 2024 · 2 comments · Fixed by #21312
Closed

Regression in mjakubowski84/parquet4s for type inference #21275

WojciechMazur opened this issue Jul 25, 2024 · 2 comments · Fixed by #21312
Assignees
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB failure in mjakubowski84/parquet4s - logs

Compiler version

Last good release: 3.4.0-RC1-bin-20231113-0dfe593-NIGHTLY
First bad release: 3.4.0-RC1-bin-20231114-18ada51-NIGHTLY
Bisect points to 6c556aa

Minimized code

// //> using dep "co.fs2::fs2-core:3.10.2"
sealed abstract class Pull[+F[_], +O, +R]:
  def >>[F2[x] >: F[x], O2 >: O, S](post: => Pull[F2, O2, S]): Pull[F2, O2, S]
object Pull:
  def eval[F[_], R](fr: F[R]): Pull[F, Nothing, R] = ???
  val done: Pull[Nothing, Nothing, Unit] = ???

class Test[F[_], T]:
  def dispose(path: String): F[Unit] = ???
  private def rotatePull(partitions: Iterable[String]): Pull[F, T, Unit] =
    partitions
      .map(partition => Pull.eval(dispose(partition)))
      .reduceOption(_ >> _)
      .getOrElse(Pull.done)

Output

-- [E007] Type Mismatch Error: /Users/wmazur/projects/sandbox/src/main/scala/usage.scala:14:16 
11 |    partitions
12 |      .map(partition => Pull.eval(dispose(partition)))
13 |      .reduceOption(_ >> _)
14 |      .getOrElse(Pull.done)
   |    ^
   |    Found:    Pull[F, Any, Unit]
   |    Required: Pull[F, T, Unit]
   |
   |    where:    F is a type in class Test with bounds <: [_] =>> Any
   |

Expectation

Should compile (probably)

Workaround:

Usage type parameter explicitly

.reduceOption[Pull[F, T, Unit]](_ >> _)
@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore labels Jul 25, 2024
@KacperFKorban
Copy link
Member

A slightly smaller minimization:

//> using scala 3.nightly

class Box[+O]:
  def ++[O2 >: O](other: Box[O2]): Box[O2] = ???
object Box:
  val empty: Box[Nothing] = ???

def test[T]: Box[T] =
  List(Box.empty, Box.empty)
    // .reduceOption[Box[T]](_ ++ _) // works
    .reduceOption(_ ++ _) // fails
    .getOrElse(Box.empty)

Output:

-- [E007] Type Mismatch Error: ~/bugs/i21275.scala:13:14 ---------------
10 |  List(Box.empty, Box.empty)
11 |    // .reduceOption[Box[T]](_ ++ _) // works
12 |    .reduceOption(_ ++ _) // fails
13 |    .getOrElse(Box.empty)
   |  ^
   |  Found:    Box[Any]
   |  Required: Box[T]
   |
   | longer explanation available when compiling with `-explain`

@Gedochao
Copy link
Contributor

cc @odersky @dwijnand

@odersky odersky self-assigned this Aug 1, 2024
@odersky odersky closed this as completed in 053c8f9 Aug 2, 2024
odersky added a commit that referenced this issue Aug 2, 2024
When we replace Nothing by a fresh type variable, we should not
accidentally instantiate that type variable to Any in case it is still
undetermined. We achieve this by giving the type variable a slightly
disguised version of Nothing which makes the compiler believe it has a
lower bound.

Fixes #21275
WojciechMazur pushed a commit that referenced this issue Aug 28, 2024
When we replace Nothing by a fresh type variable, we should not accidentally
instantiate that type variable to Any in case it is still undetermined. We achieve
this by giving the type variable a slightly disguised version of Nothing which
makes the compiler believe it has a lower bound.

Fixes #21275

[Cherry-picked 053c8f9]
@WojciechMazur WojciechMazur added this to the 3.5.2 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants