Skip to content

Pattern matching introduces unbounded existential type, losing type information #9879

Closed
@scabug

Description

@scabug

I'm confused by the following compile-time error:

private def safeMax[A](xs: List[A])(implicit ev: Ordering[A]): Option[A] = 
  xs match {
    case ys@(_ :: _) => Some(ys.min)
    case Nil               => None
  }


// Exiting paste mode, now interpreting.

<console>:12: error: No implicit Ordering defined for ?A1.
           case ys@(_ :: _) => Some(ys.min)
                                       ^

I'm not sure if it's a bug, but it seemed suspect to me.

EDIT - I first posted this question on StackOverflow - http://stackoverflow.com/questions/38775071/no-implicit-ordering-defined-on-pattern-matched-list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions