Skip to content

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

Closed
@mikearnaldi

Description

@mikearnaldi

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 |)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions