Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type parameters should be allowed on patterns #884

Open
scabug opened this issue May 10, 2008 · 4 comments
Open

Type parameters should be allowed on patterns #884

scabug opened this issue May 10, 2008 · 4 comments

Comments

@scabug
Copy link

@scabug scabug commented May 10, 2008

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.

@scabug
Copy link
Author

@scabug scabug commented May 10, 2008

@scabug
Copy link
Author

@scabug scabug commented Jul 22, 2009

@paulp said:
See also #2182.

@scabug
Copy link
Author

@scabug scabug commented Jun 16, 2015

@SethTisue said:
see also #6517

@scabug
Copy link
Author

@scabug scabug commented Mar 14, 2017

@scabug scabug added this to the Backlog milestone Apr 6, 2017
@scala scala deleted a comment from scabug Mar 18, 2018
@scala scala deleted a comment from scabug Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant