Skip to content

Type parameters should be allowed on patterns #884

Closed as not planned
Closed as not planned
@scabug

Description

@scabug

unapply methods used in patterns are allowed implicit arguments. However they're not allowed type parameters, which makes this not all that useful. For example, when helping Jan Kriesten with #882 I tried the following solution:

import scala.reflect.Manifest;

object isClass{
  def unapply[T](clazz : Class[_])(implicit man : Manifest[T]) : Option[Unit] =
    if (clazz == man.erasure) Some(()) else None
}

classOf[String] match {
  case isClass[String] => "foo"
}

Gives the error

<console>:2: error: '=>' expected but '[' found.
         case isClass[String] => "foo"

The code works if you specialise T to a String instead, so the implicits are working fine, but the inability to specify a type parameter on the pattern makes this not so useful.

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