Scala Programming Language
  1. Scala Programming Language
  2. SI-4879

Better error message when pattern matching against the companion object instead of the type

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:

      Description

      scala> case class C(a: Any)
      defined class C
      
      scala> (new C(())) match {
           |    case C =>
           | }
      <console>:9: error: pattern type is incompatible with expected type;
       found   : object C
       required: C
                case C =>
                     ^
      

      Suggested type diagnostics:

      "Note: you referred to the companion object of the class C. Perhaps you meant '_ : C' or 'C(_)'"

      /////////////////////////////////////////

      Created from Jason Zaugg comment on https://issues.scala-lang.org/browse/SI-3092?focusedCommentId=48914&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-48914

        Issue Links

          Activity

          Hide
          Commit Message Bot added a comment -

          (extempore in r25458) Better error message for case class/object match confusion.
          Closes SI-4879, no review.

          Show
          Commit Message Bot added a comment - (extempore in r25458 ) Better error message for case class/object match confusion. Closes SI-4879 , no review.

            People

            • Assignee:
              Unassigned
              Reporter:
              Simon Ochsenreither
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development