-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
area:implicitsrelated to implicitsrelated to implicitsarea:pattern-matchingarea:reportingError reporting including formatting, implicit suggestions, etcError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement
Description
I've run into this weird behavior by chance, between "old" code I had and its refactoring.
Compiler version
3.6.2-RC3
Minimized example
First, the "old" code was pattern matching an Option[(List[Int], Map[Int, Double])], but I dropped the Option, leaving just the (pair) tuple. Yet, Some in pattern matching remained:
object X:
def m(using List[Int])(using Map[Int, Double]) = {}
def apply(using t2: (List[Int], Map[Int, Double])) =
t2 match
case Some((given List[Int], given Map[Int, Double])) => m
case _ =>So I got this:
Output Error message
5 | case Some((given List[Int], given Map[Int, Double])) => m
| ^
|No given instance of type List[Int] was found for parameter x$1 of method m in object X
|
|Note: given instance given_List_Int was not considered because it was not imported with `import given`.
1 error foundWhy this Error was not helpful
Second, if I now removed the call to method m...
object X:
def m(using List[Int])(using Map[Int, Double]) = {}
def apply(using t2: (List[Int], Map[Int, Double])) =
t2 match
case Some((given List[Int], given Map[Int, Double])) =>
case _ =>.. the "correct" error is now:
-- [E030] Match case Unreachable Warning: --------------------------------------
5 | case Some((given List[Int], given Map[Int, Double])) =>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Unreachable case
-- Error: ----------------------------------------------------------------------
5 | case Some((given List[Int], given Map[Int, Double])) =>
| ^
|this case is unreachable since type (List[Int], Map[Int, Double]) is not a subclass of class Some
1 warning found
1 error foundThe first message was misleading because it actually discovered the Some-wrapped given List[Int], whereas by the second message, the case was unreachable.
I know that Scala compiler reports from "right to left", so I'm not exactly sure.
Metadata
Metadata
Assignees
Labels
area:implicitsrelated to implicitsrelated to implicitsarea:pattern-matchingarea:reportingError reporting including formatting, implicit suggestions, etcError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement