scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.85k stars 1.05k forks source link

Obscure compiler errors about higher-kinded types #19345

Open Bersier opened 9 months ago

Bersier commented 9 months ago

Compiler version

3.4.0-RC1

Minimized code

trait A[T]

type B = A | List // Error: Type argument A does not have the same kind as its bound 

def foo[C <: A, T]: C[T] = ??? // Error: type A takes type parameters

summon[A <:< A] // Error: Type argument A does not have the same kind as its bound

Expectation

Understandable error messages, similarly to:

trait A[T]

// Error: the scrutinee of a match type cannot be higher-kinded
type Foo[B <: A] = B match
  case _ => Nothing

These error messages are particularly confusing given the currently incorrect documentation about wildcard arguments.

Improved error message examples:

trait A[T]

type B = A | List // Error: components of a union type cannot be higher-kinded 

def foo[C <: A, T]: C[T] = ??? // Error: a higher-kinded type on the rhs of <: needs to be eta-expanded
// (but eta-expanding the lhs is not legal!)

summon[A <:< A] // Error: the arguments to <:< cannot be higher-kinded
Bersier commented 9 months ago

Also:

def foo(bar: [U] =>> Int => U): Nothing = ???

Error:

Missing type parameter for [U] =>> Int => U