1041 |
1041 |
1042 /** Return all exceptions in thrown list that are not in handled list. |
1042 /** Return all exceptions in thrown list that are not in handled list. |
1043 * @param thrown The list of thrown exceptions. |
1043 * @param thrown The list of thrown exceptions. |
1044 * @param handled The list of handled exceptions. |
1044 * @param handled The list of handled exceptions. |
1045 */ |
1045 */ |
1046 List<Type> unHandled(List<Type> thrown, List<Type> handled) { |
1046 List<Type> unhandled(List<Type> thrown, List<Type> handled) { |
1047 List<Type> unhandled = List.nil(); |
1047 List<Type> unhandled = List.nil(); |
1048 for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
1048 for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
1049 if (!isHandled(l.head, handled)) unhandled = unhandled.prepend(l.head); |
1049 if (!isHandled(l.head, handled)) unhandled = unhandled.prepend(l.head); |
1050 return unhandled; |
1050 return unhandled; |
1051 } |
1051 } |
1198 if (!source.allowCovariantReturns() && |
1198 if (!source.allowCovariantReturns() && |
1199 m.owner != origin && |
1199 m.owner != origin && |
1200 m.owner.isSubClass(other.owner, types)) { |
1200 m.owner.isSubClass(other.owner, types)) { |
1201 // allow limited interoperability with covariant returns |
1201 // allow limited interoperability with covariant returns |
1202 } else { |
1202 } else { |
1203 typeError(TreeInfo.diagnosticPositionFor(m, tree), |
1203 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1204 diags.fragment("override.incompatible.ret", |
1204 "override.incompatible.ret", |
1205 cannotOverride(m, other)), |
1205 cannotOverride(m, other), |
1206 mtres, otres); |
1206 mtres, otres); |
1207 return; |
1207 return; |
1208 } |
1208 } |
1209 } else if (overrideWarner.warned) { |
1209 } else if (overrideWarner.warned) { |
1210 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
1210 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
1211 "prob.found.req", |
1211 "override.unchecked.ret", |
1212 diags.fragment("override.unchecked.ret", |
1212 uncheckedOverrides(m, other), |
1213 uncheckedOverrides(m, other)), |
1213 mtres, otres); |
1214 mtres, otres); |
|
1215 } |
1214 } |
1216 |
1215 |
1217 // Error if overriding method throws an exception not reported |
1216 // Error if overriding method throws an exception not reported |
1218 // by overridden method. |
1217 // by overridden method. |
1219 List<Type> otthrown = types.subst(ot.getThrownTypes(), otvars, mtvars); |
1218 List<Type> otthrown = types.subst(ot.getThrownTypes(), otvars, mtvars); |
1220 List<Type> unhandled = unHandled(mt.getThrownTypes(), otthrown); |
1219 List<Type> unhandledErased = unhandled(mt.getThrownTypes(), types.erasure(otthrown)); |
1221 if (unhandled.nonEmpty()) { |
1220 List<Type> unhandledUnerased = unhandled(mt.getThrownTypes(), otthrown); |
|
1221 if (unhandledErased.nonEmpty()) { |
1222 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1222 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1223 "override.meth.doesnt.throw", |
1223 "override.meth.doesnt.throw", |
1224 cannotOverride(m, other), |
1224 cannotOverride(m, other), |
1225 unhandled.head); |
1225 unhandledUnerased.head); |
|
1226 return; |
|
1227 } |
|
1228 else if (unhandledUnerased.nonEmpty()) { |
|
1229 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
|
1230 "override.unchecked.thrown", |
|
1231 cannotOverride(m, other), |
|
1232 unhandledUnerased.head); |
1226 return; |
1233 return; |
1227 } |
1234 } |
1228 |
1235 |
1229 // Optional warning if varargs don't agree |
1236 // Optional warning if varargs don't agree |
1230 if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) |
1237 if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) |