@@ -1064,6 +1064,11 @@ trait Applications extends Compatibility {
1064
1064
if (! tree.tpe.isError && tree.tpe.isErroneous) tree
1065
1065
else errorTree(tree, NotAnExtractor (qual))
1066
1066
1067
+ def reportErrors (tree : Tree , state : TyperState ) =
1068
+ assert(state.reporter.hasErrors)
1069
+ state.reporter.flush()
1070
+ tree
1071
+
1067
1072
/** If this is a term ref tree, try to typecheck with its type name.
1068
1073
* If this refers to a type alias, follow the alias, and if
1069
1074
* one finds a class, reference the class companion module.
@@ -1097,42 +1102,52 @@ trait Applications extends Compatibility {
1097
1102
* overloaded unapply does *not* need to be applicable to its argument
1098
1103
* whereas overloaded variants need to have a conforming variant.
1099
1104
*/
1100
- def trySelectUnapply (qual : untpd.Tree )(fallBack : Tree => Tree ): Tree = {
1105
+ def trySelectUnapply (qual : untpd.Tree )(fallBack : ( Tree , TyperState ) => Tree ): Tree = {
1101
1106
// try first for non-overloaded, then for overloaded ocurrences
1102
- def tryWithName (name : TermName )(fallBack : Tree => Tree )(implicit ctx : Context ): Tree = {
1107
+ def tryWithName (name : TermName )(fallBack : ( Tree , TyperState ) => Tree )(implicit ctx : Context ): Tree = {
1103
1108
def tryWithProto (pt : Type )(implicit ctx : Context ) = {
1104
1109
val result = typedExpr(untpd.Select (qual, name), new UnapplyFunProto (pt, this ))
1105
- if (! result.symbol.exists || result.symbol.name == name) result
1110
+ if ! result.symbol.exists
1111
+ || result.symbol.name == name
1112
+ || ctx.reporter.hasErrors
1113
+ then result
1106
1114
else notAnExtractor(result)
1107
1115
// It might be that the result of typedExpr is an `apply` selection or implicit conversion.
1108
1116
// Reject in this case.
1109
1117
}
1110
1118
tryEither {
1111
1119
tryWithProto(selType)
1112
1120
} {
1113
- (sel, _ ) =>
1121
+ (sel, state ) =>
1114
1122
tryEither {
1115
1123
tryWithProto(WildcardType )
1116
1124
} {
1117
- (_, _) => fallBack(sel)
1125
+ (_, _) => fallBack(sel, state )
1118
1126
}
1119
1127
}
1120
1128
}
1121
1129
1122
1130
// try first for unapply, then for unapplySeq
1123
1131
tryWithName(nme.unapply) {
1124
- sel => tryWithName(nme.unapplySeq)(_ => fallBack(sel)) // for backwards compatibility; will be dropped
1132
+ (sel, state) =>
1133
+ tryWithName(nme.unapplySeq) {
1134
+ (_, _) => fallBack(sel, state)
1135
+ }
1125
1136
}
1126
1137
}
1127
1138
1128
1139
/** Produce a typed qual.unapply or qual.unapplySeq tree, or
1129
1140
* else if this fails follow a type alias and try again.
1130
1141
*/
1131
- var unapplyFn = trySelectUnapply(qual) { sel =>
1132
- val qual1 = followTypeAlias(qual)
1133
- if (qual1.isEmpty) notAnExtractor(sel)
1134
- else trySelectUnapply(qual1)(_ => notAnExtractor(sel))
1135
- }
1142
+ var unapplyFn =
1143
+ trySelectUnapply(qual) {
1144
+ (sel, state) =>
1145
+ val qual1 = followTypeAlias(qual)
1146
+ if (qual1.isEmpty) reportErrors(sel, state)
1147
+ else trySelectUnapply(qual1) {
1148
+ (_, state) => reportErrors(sel, state)
1149
+ }
1150
+ }
1136
1151
1137
1152
/** Add a `Bind` node for each `bound` symbol in a type application `unapp` */
1138
1153
def addBinders (unapp : Tree , bound : List [Symbol ]) = unapp match {
0 commit comments