8057650: uniform error diagnostics for inconsistent inherited method signatures

Consolidate diagnostics for bad overrides

Reviewed-by: vromero
This commit is contained in:
Maurizio Cimadamore 2017-12-20 15:33:31 +00:00
parent f06ebe9b3a
commit ede41aa311
23 changed files with 52 additions and 41 deletions

View File

@ -1976,8 +1976,8 @@ public class Check {
types.covariantReturnType(rt2, rt1, types.noWarnings)) ||
checkCommonOverriderIn(s1,s2,site);
if (!compat) {
log.error(pos, Errors.TypesIncompatibleDiffRet(t1, t2, s2.name +
"(" + types.memberType(t2, s2).getParameterTypes() + ")"));
log.error(pos, Errors.TypesIncompatible(t1, t2,
Fragments.IncompatibleDiffRet(s2.name, types.memberType(t2, s2).getParameterTypes())));
return s2;
}
} else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) &&
@ -2563,20 +2563,22 @@ public class Check {
//strong semantics - issue an error if two sibling interfaces
//have two override-equivalent defaults - or if one is abstract
//and the other is default
String errKey;
Fragment diagKey;
Symbol s1 = defaults.first();
Symbol s2;
if (defaults.size() > 1) {
errKey = "types.incompatible.unrelated.defaults";
s2 = defaults.toList().tail.head;
diagKey = Fragments.IncompatibleUnrelatedDefaults(Kinds.kindName(site.tsym), site,
m.name, types.memberType(site, m).getParameterTypes(),
s1.location(), s2.location());
} else {
errKey = "types.incompatible.abstract.default";
s2 = abstracts.first();
diagKey = Fragments.IncompatibleAbstractDefault(Kinds.kindName(site.tsym), site,
m.name, types.memberType(site, m).getParameterTypes(),
s1.location(), s2.location());
}
log.error(pos, errKey,
Kinds.kindName(site.tsym), site,
m.name, types.memberType(site, m).getParameterTypes(),
s1.location(), s2.location());
log.error(pos, Errors.TypesIncompatible(s1.location().type, s2.location().type, diagKey));
break;
}
}

View File

@ -1136,16 +1136,21 @@ compiler.err.type.var.more.than.once=\
compiler.err.type.var.more.than.once.in.result=\
type variable {0} occurs more than once in type of {1}; cannot be left uninstantiated
# 0: type, 1: type, 2: string
compiler.err.types.incompatible.diff.ret=\
types {0} and {1} are incompatible; both define {2}, but with unrelated return types
# 0: type, 1: type, 2: fragment
compiler.err.types.incompatible=\
types {0} and {1} are incompatible;\n\
{2}
# 0: name, 1: list of type
compiler.misc.incompatible.diff.ret=\
both define {0}({1}), but with unrelated return types
# 0: kind name, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol
compiler.err.types.incompatible.unrelated.defaults=\
compiler.misc.incompatible.unrelated.defaults=\
{0} {1} inherits unrelated defaults for {2}({3}) from types {4} and {5}
# 0: kind name, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol
compiler.err.types.incompatible.abstract.default=\
compiler.misc.incompatible.abstract.default=\
{0} {1} inherits abstract and default for {2}({3}) from types {4} and {5}
# 0: name, 1: kind name, 2: symbol

View File

@ -1,2 +1,2 @@
BadCovar.java:22:10: compiler.err.types.incompatible.diff.ret: bad.covar.B, bad.covar.A, f()
BadCovar.java:22:10: compiler.err.types.incompatible: bad.covar.B, bad.covar.A, (compiler.misc.incompatible.diff.ret: f, )
1 error

View File

@ -1,2 +1,2 @@
InconsistentInheritedSignature.java:17:1: compiler.err.types.incompatible.diff.ret: I2, I1, f()
InconsistentInheritedSignature.java:17:1: compiler.err.types.incompatible: I2, I1, (compiler.misc.incompatible.diff.ret: f, )
1 error

View File

@ -1,2 +1,2 @@
InconsistentReturn.java:17:1: compiler.err.types.incompatible.diff.ret: I2, I1, f()
InconsistentReturn.java:17:1: compiler.err.types.incompatible: I2, I1, (compiler.misc.incompatible.diff.ret: f, )
1 error

View File

@ -1,2 +1,2 @@
Neg01.java:14:12: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg01.AB, m, , Neg01.IA, Neg01.IB
Neg01.java:14:12: compiler.err.types.incompatible: Neg01.IA, Neg01.IB, (compiler.misc.incompatible.unrelated.defaults: kindname.class, Neg01.AB, m, , Neg01.IA, Neg01.IB)
1 error

View File

@ -1,2 +1,2 @@
Neg02.java:16:13: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg02.X, m, , Neg02.A, Neg02.B
Neg02.java:16:13: compiler.err.types.incompatible: Neg02.A, Neg02.B, (compiler.misc.incompatible.unrelated.defaults: kindname.class, Neg02.X, m, , Neg02.A, Neg02.B)
1 error

View File

@ -1,2 +1,2 @@
Neg14.java:10:14: compiler.err.types.incompatible.abstract.default: kindname.class, Neg14.AB, m, , Neg14.IB, Neg14.IA
Neg14.java:10:14: compiler.err.types.incompatible: Neg14.IB, Neg14.IA, (compiler.misc.incompatible.abstract.default: kindname.class, Neg14.AB, m, , Neg14.IB, Neg14.IA)
1 error

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.types.incompatible.diff.ret
// key: compiler.err.types.incompatible
// key: compiler.misc.incompatible.diff.ret
// key: compiler.err.prob.found.req
// key: compiler.misc.incompatible.descs.in.functional.intf
// key: compiler.misc.descriptor

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.types.incompatible.diff.ret
// key: compiler.err.types.incompatible
// key: compiler.misc.incompatible.diff.ret
interface A {
int m();

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.types.incompatible.abstract.default
// key: compiler.err.types.incompatible
// key: compiler.misc.incompatible.abstract.default
class TypesIncompatibleAbstractDefault {
interface A {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.types.incompatible.unrelated.defaults
// key: compiler.err.types.incompatible
// key: compiler.misc.incompatible.unrelated.defaults
class TypesIncompatibleUnrelatedDefaults {
interface A {

View File

@ -1,2 +1,2 @@
T6294779c.java:29:5: compiler.err.types.incompatible.diff.ret: T6294779c.I2, T6294779c.I1, get()
T6294779c.java:29:5: compiler.err.types.incompatible: T6294779c.I2, T6294779c.I1, (compiler.misc.incompatible.diff.ret: get, )
1 error

View File

@ -1,2 +1,2 @@
T4717181c.java:15:21: compiler.err.types.incompatible.diff.ret: T4717181c.A<java.lang.Integer>, T4717181c.A<java.lang.Integer>, f(java.lang.Integer)
T4717181c.java:15:21: compiler.err.types.incompatible: T4717181c.A<java.lang.Integer>, T4717181c.A<java.lang.Integer>, (compiler.misc.incompatible.diff.ret: f, java.lang.Integer)
1 error

View File

@ -1,6 +1,6 @@
Test3.java:14:1: compiler.err.types.incompatible.diff.ret: B, A, m()
Test3.java:19:1: compiler.err.types.incompatible.diff.ret: D, C, m()
Test3.java:27:1: compiler.err.types.incompatible.diff.ret: E<T>, B, m()
Test3.java:33:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
Test3.java:37:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
Test3.java:14:1: compiler.err.types.incompatible: B, A, (compiler.misc.incompatible.diff.ret: m, )
Test3.java:19:1: compiler.err.types.incompatible: D, C, (compiler.misc.incompatible.diff.ret: m, )
Test3.java:27:1: compiler.err.types.incompatible: E<T>, B, (compiler.misc.incompatible.diff.ret: m, )
Test3.java:33:1: compiler.err.types.incompatible: F<V>, E<U>, (compiler.misc.incompatible.diff.ret: m, )
Test3.java:37:1: compiler.err.types.incompatible: F<V>, E<U>, (compiler.misc.incompatible.diff.ret: m, )
5 errors

View File

@ -1,2 +1,2 @@
T4856983a.java:13:6: compiler.err.types.incompatible.diff.ret: I2, I1, m()
T4856983a.java:13:6: compiler.err.types.incompatible: I2, I1, (compiler.misc.incompatible.diff.ret: m, )
1 error

View File

@ -1,2 +1,2 @@
T4856983b.java:12:24: compiler.err.types.incompatible.diff.ret: I2, I1, m()
T4856983b.java:12:24: compiler.err.types.incompatible: I2, I1, (compiler.misc.incompatible.diff.ret: m, )
1 error

View File

@ -1,2 +1,2 @@
T6199146.java:9:25: compiler.err.types.incompatible.diff.ret: T6199146.I2, T6199146.I1, getFoo()
T6199146.java:9:25: compiler.err.types.incompatible: T6199146.I2, T6199146.I1, (compiler.misc.incompatible.diff.ret: getFoo, )
1 error

View File

@ -1,2 +1,2 @@
T7034495.java:40:17: compiler.err.types.incompatible.diff.ret: T7034495.B<compiler.misc.type.captureof: 1, ?>, T7034495.A<compiler.misc.type.captureof: 2, ?>, foo()
T7034495.java:40:17: compiler.err.types.incompatible: T7034495.B<compiler.misc.type.captureof: 1, ?>, T7034495.A<compiler.misc.type.captureof: 2, ?>, (compiler.misc.incompatible.diff.ret: foo, )
1 error

View File

@ -1,3 +1,3 @@
BadConv04.java:19:5: compiler.err.types.incompatible.diff.ret: BadConv04.I2, BadConv04.I1, m()
BadConv04.java:19:5: compiler.err.types.incompatible: BadConv04.I2, BadConv04.I1, (compiler.misc.incompatible.diff.ret: m, )
BadConv04.java:21:13: compiler.err.prob.found.req: (compiler.misc.incompatible.descs.in.functional.intf: kindname.interface, BadConv04.SAM,{(compiler.misc.descriptor: m, , long, ),(compiler.misc.descriptor: m, , int, )})
2 errors

View File

@ -1001,18 +1001,18 @@ public class BridgeMethodsTemplateTest extends BridgeMethodTestCase {
public void testA5() throws IOException, ReflectiveOperationException {
compileSpec("C(A(Id0),Jd0)",
"compiler.err.types.incompatible.unrelated.defaults");
"compiler.err.types.incompatible");
}
public void testA6() throws IOException, ReflectiveOperationException {
compileSpec("C(A(Ia0,Jd0))",
"compiler.err.does.not.override.abstract",
"compiler.err.types.incompatible.abstract.default");
"compiler.err.types.incompatible");
}
public void testA7() throws IOException, ReflectiveOperationException {
compileSpec("C(A(Id0,Jd0))",
"compiler.err.types.incompatible.unrelated.defaults");
"compiler.err.types.incompatible");
}
public void testA8() throws IOException, ReflectiveOperationException {

View File

@ -1,4 +1,4 @@
NonSAM2.java:13:1: compiler.err.types.incompatible.diff.ret: Bar1, Foo1, getAge(java.lang.String)
NonSAM2.java:13:1: compiler.err.types.incompatible: Bar1, Foo1, (compiler.misc.incompatible.diff.ret: getAge, java.lang.String)
NonSAM2.java:15:1: compiler.err.name.clash.same.erasure.no.override: getOldest, java.util.List<?>, C, getOldest, java.util.List<java.lang.Number>, A
NonSAM2.java:17:1: compiler.err.name.clash.same.erasure.no.override: getOldest, java.util.List<java.lang.Integer>, D, getOldest, java.util.List<java.lang.Number>, A
NonSAM2.java:21:1: compiler.err.name.clash.same.erasure.no.override: m, T2, Bar2, m, T1, Foo2

View File

@ -1,2 +1,2 @@
T4.java:3:10: compiler.err.types.incompatible.diff.ret: iclss01004_2, iclss01004_1, foo(int)
T4.java:3:10: compiler.err.types.incompatible: iclss01004_2, iclss01004_1, (compiler.misc.incompatible.diff.ret: foo, int)
1 error