@@ -1066,22 +1066,28 @@ trait Applications extends Compatibility {
1066
1066
if (! tree.tpe.isError && tree.tpe.isErroneous) tree
1067
1067
else errorTree(tree, NotAnExtractor (qual))
1068
1068
1069
+ /** Does `state` contain a single "NotAMember" message as pending error message
1070
+ * that says `$membername is not a member of ...` ?
1071
+ */
1072
+ def saysNotAMember (state : TyperState , memberName : TermName ): Boolean =
1073
+ state.reporter.pendingMessages match
1074
+ case msg :: Nil =>
1075
+ msg.contained match
1076
+ case NotAMember (_, name, _, _) => name == memberName
1077
+ case _ => false
1078
+ case _ => false
1079
+
1069
1080
/** Report errors buffered in state.
1070
1081
* @pre state has errors to report
1071
1082
* If there is a single error stating that "unapply" is not a member, print
1072
1083
* the more informative "notAnExtractor" message instead.
1073
1084
*/
1074
1085
def reportErrors (tree : Tree , state : TyperState ): Tree =
1075
1086
assert(state.reporter.hasErrors)
1076
- val msgs = state.reporter.removeBufferedMessages
1077
- msgs match
1078
- case msg :: Nil =>
1079
- msg.contained match
1080
- case NotAMember (_, nme.unapply, _, _) => return notAnExtractor(tree)
1081
- case _ =>
1082
- case _ =>
1083
- msgs.foreach(ctx.reporter.report)
1084
- tree
1087
+ if saysNotAMember(state, nme.unapply) then notAnExtractor(tree)
1088
+ else
1089
+ state.reporter.flush()
1090
+ tree
1085
1091
1086
1092
/** If this is a term ref tree, try to typecheck with its type name.
1087
1093
* If this refers to a type alias, follow the alias, and if
@@ -1145,7 +1151,12 @@ trait Applications extends Compatibility {
1145
1151
tryWithName(nme.unapply) {
1146
1152
(sel, state) =>
1147
1153
tryWithName(nme.unapplySeq) {
1148
- (_, _) => fallBack(sel, state)
1154
+ (sel2, state2) =>
1155
+ // if both fail, return unapply error, unless that is simply a
1156
+ // "not a member", and the unapplySeq error is more refined.
1157
+ if saysNotAMember(state, nme.unapply) && ! saysNotAMember(state2, nme.unapplySeq)
1158
+ then fallBack(sel2, state2)
1159
+ else fallBack(sel, state)
1149
1160
}
1150
1161
}
1151
1162
}
0 commit comments