scala/scala3

Partial application of bounded type operator fails bounds check

Open

#9,695 opened on Sep 1, 2020

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Scala (6,247 stars) (1,159 forks)batch import
area:typerbackloghelp wanteditype:bug

Description

There seems to be some inconsistency between curried and uncurried type operators. This means that partially applying certain operators fails.

Minimized code

object Test {
  type Foo[+A, +B <: A] = B               // uncurried -> OK
  type Bar[+A] = [B <: A] =>> Foo[A, B]   // curried   -> fails
}

Output

-- Error: CurryingOps.scala:3:12 -----------------------------------------------
3 |  type Bar[+A] = [B <: A] =>> Foo[A, B]   // curried   -> fails
  |           ^^
  |covariant type parameter A occurs in contravariant position in [B <: A] =>> Test.Foo[A, B]
1 error found

Expectation

I'd expect the two versions to behave the same. The definition of Foo is correct, IMO. The type A does not appear in a contravariant position inside the definition/body of Foo — in fact it doesn't appear at all. It does appear in a bound in the signature of Foo but that shouldn't matter (the signature is not part of the definition). That means that the error in Bar is probably a false negative. I'm not sure why the bounds of type lambdas are considered in variance checking.

This may or may not be related to #6320 and #6499.

Tagging @Blaisorblade and @smarter since the example resulted from a discussion we had about variance checking.

Contributor guide