Skip to content

Monomorphism check missing on anonymous fns #2495

Closed
@japgolly

Description

@japgolly

Consider this snippet:

object TypeParam {

  sealed trait F[A]
  case object FI extends F[Int]
  case object FS extends F[String]

  trait FFn { def apply[A](f: F[A]): A }

  val test4: FFn = {
    case FI => 1
    case FS => ""
  }
}

In scalac it fails saying:

  // [error] missing parameter type for expanded function
  // [error] The argument types of an anonymous function must be fully known. (SLS 8.5)
  // [error] Expected type was: TypeParam.FFn
  // [error]   val test4: FFn = {
  // [error]                    ^

In dotc it fails saying:

-- Error: <console>:9:6 --------------------------------------------------------
9 |      case FI => 1
  |      ^
  |     missing parameter type for parameter x$1 of expanded function x$1 => 
  |       x$1 match 
  |         {
  |           case FI => 
  |             1
  |           case FS => 
  |             ""
  |         }, expected = FFn

which is much more confusing a message. It seems a monomorphism check is present in Scala and provides a specific error message where as in Dotty it's missing then fails further down the line.

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