Skip to content

"<type alias> does not take type parameters" when type parameter is same as the companion object for top-level type aliases #23752

@unkarjedy

Description

@unkarjedy

Scala 3.7.2

Notice that MyOutputAlias2[MyType] is not compiled when put inside MyType.
I am not 100% sure it's against some part of specification, but it feels off.
I noticed this inconsistency while playing around with example from SCL-22391

trait MyOutput[T]
final type MyOutputAlias1[T] = MyOutput[T]
final type MyOutputAlias2 = MyOutput

trait MyType
object MyType {
  val value1: MyOutput[MyType] = ???
  val value2: MyOutputAlias1[MyType] = ???
  val value3: MyOutputAlias2[MyType] = ??? // COMPILATION ERROR
}

val value1: MyOutput[MyType] = ???
val value2: MyOutputAlias1[MyType] = ???
val value3: MyOutputAlias2[MyType] = ???
Image

Note, all is fine if you wrap the code (making the type alias non-top-level)

object wrapper {
  trait MyOutput[T]
  final type MyOutputAlias1[T] = MyOutput[T]
  final type MyOutputAlias2 = MyOutput

  trait MyType
  object MyType {
    val value1: MyOutput[MyType] = ???
    val value2: MyOutputAlias1[MyType] = ???
    val value3: MyOutputAlias2[MyType] = ???
  }

  val value1: MyOutput[MyType] = ???
  val value2: MyOutputAlias1[MyType] = ???
  val value3: MyOutputAlias2[MyType] = ???
}
Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions