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

Inconsistent Behaviour in Union and Intersection Types with compiler crashes #12896

Closed
mikearnaldi opened this issue Jun 22, 2021 · 4 comments · Fixed by #14873
Closed

Inconsistent Behaviour in Union and Intersection Types with compiler crashes #12896

mikearnaldi opened this issue Jun 22, 2021 · 4 comments · Fixed by #14873
Assignees

Comments

@mikearnaldi
Copy link

Compiler version

3.0.0

Minimized code

Minimal repros:

  1. https://github.com/Matechs-Garage/scala-3-zio/blob/scala-bug-union/src/main/scala/Main.scala
  2. https://github.com/Matechs-Garage/scala-3-zio/blob/scala-bug-has/src/main/scala/Main.scala

Output

  1. crashes with https://github.com/Matechs-Garage/scala-3-zio/blob/scala-bug-union/error.log, some unions have duplicates as per comments in code.

  2. main type is inferred as IO[Nothing, Nothing, Unit] meaning the compiler has inferred X to be Nothing in Has[Math] & X => Has[Math] & Has[Console]

Expectation

  1. shouldn't crash and union types should not show duplicates

  2. removing Has from the code like in https://github.com/Matechs-Garage/scala-3-zio/blob/scala-ok-intersection/src/main/scala/Main.scala correctly infer X to Console in Math & X => Math & Console


The master branch contains a "kind of working" variant of the expected behavior worked around by playing with the parameter variance (even though it shouldn't be needed given & and |)

@smarter
Copy link
Member

smarter commented Jun 22, 2021

Is 2. the same issue as #12077 ?

@smarter
Copy link
Member

smarter commented Jun 22, 2021

Minimized 1. (which I'll take this issue to be about, if there are other issues they need to be opened separately):

trait IO[E] {
  def map[B](f: Any => B): IO[E] = ???
  def flatMap[C](f: Any => IO[C]): IO[E | C] = ???
}

class Test {
  def test: Unit = {
    val a: IO[Nothing] = ???

    val d = a.flatMap(y => a.flatMap(z => a.map(_ => z)))
  }
}

@smarter
Copy link
Member

smarter commented Jun 22, 2021

This is likely an instance of #8900

@smarter smarter self-assigned this Jun 22, 2021
@mikearnaldi
Copy link
Author

Is 2. the same issue as #12077 ?

It seem related I can't say if it is 100% the same but it appears so

odersky added a commit to dotty-staging/dotty that referenced this issue Apr 7, 2022
michelou pushed a commit to michelou/dotty that referenced this issue Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants