Skip to content

Type inference too imprecise when approximating union of abstract types #998

Closed
@smarter

Description

@smarter

In this example, elem is inferred to be of type Any instead of type X as in Scala 2:

object Test {
  def foo[A <: X, B <: X, X](left: A, right: B): Unit = {
    val elem = if (false) left else right
  }
}

The issue is in TypeOps#approximateUnion, we approximate a union of types using the intersection of the base classes of the types, but that's not correct when the types are bounded by abstract types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions