@@ -28,7 +28,7 @@ import collection.mutable
2828import config .Printers .{overload , typr , unapp }
2929import TypeApplications ._
3030
31- import reporting .diagnostic .Message
31+ import reporting .diagnostic .{ Message , messages }
3232import reporting .trace
3333import Constants .{Constant , IntTag , LongTag }
3434import dotty .tools .dotc .reporting .diagnostic .messages .{UnapplyInvalidReturnType , NotAnExtractor , UnapplyInvalidNumberOfArguments }
@@ -1058,15 +1058,27 @@ trait Applications extends Compatibility {
10581058 record(" typedUnApply" )
10591059 val Apply (qual, args) = tree
10601060
1061- def notAnExtractor (tree : Tree ) =
1061+ def notAnExtractor (tree : Tree ): Tree =
10621062 // prefer inner errors
10631063 // e.g. report not found ident instead of not an extractor in tests/neg/i2950.scala
10641064 if (! tree.tpe.isError && tree.tpe.isErroneous) tree
10651065 else errorTree(tree, NotAnExtractor (qual))
10661066
1067- def reportErrors (tree : Tree , state : TyperState ) =
1067+ /** Report errors buffered in state.
1068+ * @pre state has errors to report
1069+ * If there is a single error stating that "unapply" is not a member, print
1070+ * the more informative "notAnExtractor" message instead.
1071+ */
1072+ def reportErrors (tree : Tree , state : TyperState ): Tree =
10681073 assert(state.reporter.hasErrors)
1069- state.reporter.flush()
1074+ val msgs = state.reporter.removeBufferedMessages
1075+ msgs match
1076+ case msg :: Nil =>
1077+ msg.contained match
1078+ case messages.NotAMember (_, nme.unapply, _, _) => return notAnExtractor(tree)
1079+ case _ =>
1080+ case _ =>
1081+ msgs.foreach(ctx.reporter.report)
10701082 tree
10711083
10721084 /** If this is a term ref tree, try to typecheck with its type name.
0 commit comments