scala/scala3

Partial application of bounded type operator fails bounds check

Open

#9.695 geöffnet am 1. Sept. 2020

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Scala (1.159 Forks)batch import
area:typerbackloghelp wanteditype:bug

Repository-Metriken

Stars
 (6.247 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 18T 14h) (133 gemergte PRs in 30 T)

Beschreibung

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