Skip to content

Bad type inference when type parameter as existential bound has invariant position #10740

@joroKr21

Description

@joroKr21

Compiles in dotty:

  def diff1[A](xs: Set[A], ys: Set[_ <: A]) = xs -- ys
  def diff2[A](xs: Set[_ >: A], ys: Set[A]) = xs -- ys
  def diff3[A](xs: Set[_ >: A], ys: Set[_ <: A]) = xs -- ys
  val xs = Set(Option(42))
  val ys = Set(Some(42))
  diff1(xs, ys)
  diff2(xs, ys) // type mismatch: A is inferred as Option[Int]
  diff3(xs, ys)

Adapted from #5559 (comment)

Cause is similar to #10686 - when solving type variables the order of constraints matters.
Variables being solved here come from ExistentialType.withTypeVars.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions