Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 25153 - Request better compiler message for shadowed methods
Summary: Request better compiler message for shadowed methods
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-21 19:04 EDT by Eric Nickell CLA
Modified: 2014-05-06 13:08 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Nickell CLA 2002-10-21 19:04:25 EDT
I was surprised that the following would not compile:

public class AOuter {

	
	protected abstract class AInner {
		protected abstract void action();
	
		protected final double someFunction() {
			return someFunction("whatever");
		}
	}

	public double someFunction(String name) {
		if ("half".equals(name)) return 0.5;
		return 0.0;
	}
	
}
Comment 1 Eric Nickell CLA 2002-10-21 21:08:27 EDT
(I'm also surprised that bugzilla keeps cutting off my comments without
notification.  Now I have to reconstruct the rest of my previous message.)

In essence, javac gives the same error. Both are in line with JLS, which says
that a method of a given name "shadows" all methods of the same name in an
enclosing class.  (This is even though the methods in the enclosing class may
have different signatures.)

Since this was a surprise to me, I suspect that this aspect of shadowing is not
well-understood, and that eclipse users would be well-served if the compiler
message would use the term "shadow" so that users can understand what's going
wrong by indexing JLS.  For example:
  "Method someFunction(java.lang.String) in type compilerBugs.AOuter is shadowed
and inaccessible via simple name within type compilerBugs.AOuter.AInner"

Obviously, it would only be appropriate to use if a method of the correct
signature existed, but was inaccessible due to shadowing.
Comment 2 Kent Johnson CLA 2002-11-19 13:54:26 EST
The method lookup never reaches the outer type since it finds a selector match 
with 'someFunction'. We never find the outer implementation.

Java has its roots in C++ which did function name overloading, not in Smalltalk 
which was a pure OO language and considered a method's signature to be more 
than its selector.

I accept that some users may find this confusing depending on their background, 
but we need to keep our error messages in line with javac.
Comment 3 Philipe Mulet CLA 2002-11-20 05:30:13 EST
Indeed, the namelookup process cannot be used to achieve this, since it doesn't 
reach the outer method.

However, maybe the method verification process could provide an optional hint 
about this (like we do when warning about overriding package default methods 
across packages).

Time permitting for 2.1, but likely we will keep for later.
Comment 4 Kent Johnson CLA 2002-11-20 15:01:52 EST
Phillipe: Do you want to tag all methods which 'shadow' an inherited method 
with an incompatible signature? Or just methods defined by nested types?

In other words, should we detect & report a warning against foo(String):

class A {
void foo() {}
}

class B extends A {
void foo(String s) {}
}
Comment 5 Philipe Mulet CLA 2003-02-14 06:06:09 EST
I would only report in the nested scenario. This is likely a collision 
situation which would remain local to the same unit.

I would actually not do it for 2.1, but keep it for 2.2 unless it is trivial 
(no new code to add)
Comment 6 Philipe Mulet CLA 2004-05-19 10:54:32 EDT
Deferred
Comment 7 Denis Roy CLA 2009-08-30 02:13:50 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.