Skip to content

Wrong error message in pattern matching where "not found" would be expected #5101

Closed
@Duhemm

Description

@Duhemm

The following snippet is correctly rejected by the compiler, but the error message is confusing:

object Bar {
  trait A
  case class A0(foo: Int) extends A
}

object Foo {
  import Bar.A

  def buzz(a: A) = {
    a match {
      case A0(_) =>
    }
  }
}
-- Error: Foo.scala:11:11 ------------------------------------------------------                   
11 |      case A0(_) =>                                                                            
   |           ^^                                                                                  
   |A0 cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method
one error found

A0 defines an unapply method, so the error message is wrong. The actual problem is that A0 is simply not in scope.

The error message that I would expect is:

-- Error: Foo.scala:11:11 ------------------------------------------------------                   
11 |      case A0(_) =>                                                                            
   |           ^^                                                                                  
   |           not found: A0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions