Skip to content

Variance checking inconsistency when using type members in refinement types in argument position #9725

@scabug

Description

@scabug
trait Foo1[-X] { def bar[Y <: X](y: Y) = y } // typechecks

// A variant of Foo1 encoding the type parameter Y using a dependent method type.
// error: contravariant type X occurs in covariant position in type  <: X of type Y
trait Foo2[-X] { def bar(x: { type Y <: X })(y: x.Y) = y } 

trait Foo3[+X] { def bar[Y >: X](y: Y) = y } // typechecks

// A variant of Foo3 using a dependent method type.
// error: covariant type X occurs in contravariant position in type  >: X of type Y
trait Foo4[+X] { def bar(x: { type Y >: X })(y: x.Y) = y }

The errors appear even if we don't use dependent method types.

// error: covariant type X occurs in contravariant position in type  >: X of type Y
trait Foo9[+X] { def bar(x: { type Y >: X }): Any }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions