8139255: javac reports "cannot override" messages instead of "cannot hide" messages for static methods

Improve clarity of javac messages by discriminating hiding scenerio from overriding

Reviewed-by: mcimadamore, sadayapalam
This commit is contained in:
Srinivas Dama 2015-11-12 08:39:23 +05:30 committed by Srikanth Adayapalam
parent 431aa657a6
commit 9bf5e9c8f4
6 changed files with 66 additions and 6 deletions

View file

@ -1730,11 +1730,18 @@ public class Check {
boolean resultTypesOK =
types.returnTypeSubstitutable(mt, ot, otres, overrideWarner);
if (!resultTypesOK) {
if ((m.flags() & STATIC) != 0 && (other.flags() & STATIC) != 0) {
log.error(TreeInfo.diagnosticPositionFor(m, tree),
Errors.OverrideIncompatibleRet(Fragments.CantHide(m, m.location(), other,
other.location()), mtres, otres));
m.flags_field |= BAD_OVERRIDE;
} else {
log.error(TreeInfo.diagnosticPositionFor(m, tree),
"override.incompatible.ret",
cannotOverride(m, other),
mtres, otres);
m.flags_field |= BAD_OVERRIDE;
}
return;
} else if (overrideWarner.hasNonSilentLint(LintCategory.UNCHECKED)) {
warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree),

View file

@ -2283,6 +2283,10 @@ compiler.warn.override.equals.but.not.hashcode=\
compiler.misc.cant.override=\
{0} in {1} cannot override {2} in {3}
# 0: symbol, 1: symbol, 2: symbol, 3: symbol
compiler.misc.cant.hide=\
{0} in {1} cannot hide {2} in {3}
# 0: symbol, 1: symbol, 2: symbol, 3: symbol
compiler.misc.cant.implement=\
{0} in {1} cannot implement {2} in {3}

View file

@ -1,2 +1,2 @@
T4720359a.java:16:23: compiler.err.override.incompatible.ret: (compiler.misc.cant.override: m(), p1.T4720359c, m(), p1.T4720359a), int, void
T4720359a.java:16:23: compiler.err.override.incompatible.ret: (compiler.misc.cant.hide: m(), p1.T4720359c, m(), p1.T4720359a), int, void
1 error

View file

@ -0,0 +1,14 @@
/*
* @test /nodynamiccopyright/
* @bug 8139255
* @summary javac emits diagnostic message as overriding instead of hiding for class methods.
* @compile/fail/ref=T8139255.out -XDrawDiagnostics T8139255.java
*/
public class T8139255 {
static void func() { }
}
class T8139255_1 extends T8139255 {
static int func() { return 0; }
}

View file

@ -0,0 +1,2 @@
T8139255.java:13:15: compiler.err.override.incompatible.ret: (compiler.misc.cant.hide: func(), T8139255_1, func(), T8139255), int, void
1 error

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.override.incompatible.ret
// key: compiler.misc.cant.hide
class Base {
static void func() { }
}
class HideStatic extends Base {
static int func() { return 0; }
}