Bug 98532 - [1.5][compiler] Spurious 'type parameter T is hiding the type T' warning for static nested classes
Summary: [1.5][compiler] Spurious 'type parameter T is hiding the type T' warning for ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.1.1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-06 11:32 EDT by David Mandelin CLA
Modified: 2006-02-16 15:21 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Mandelin CLA 2005-06-06 11:32:56 EDT
See comments in test code snippet:

public class Gen<T> {
	static class StaticInnerNoParam {
                // Compiler error on the following line -- 
                // "Cannot make a static reference to non-static type T"
                // This is expected
		T x;
	}

        // Warning reported on the following line --
        // "The type parameter T is hiding the type T" 
        // Perhaps this is technically true? (I'm not quite sure what
        //     the Java spec says about this.) But the outer T cannot
        //     be used in this scope anyway, so it seems that the
        //     warning is not really beneficial. I use the same names
        //     for corresponding type parameters between the outer
        //     class and static inner classes, so this generates
        //     unnecessary warnings for me.
	static class StaticInnerParam<T> {
	
	}
}
Comment 1 Philipe Mulet CLA 2005-06-09 06:00:32 EDT
I agree we shouldn't complain about hiding here, as outer T isn't accessible in
context.
Comment 2 Philipe Mulet CLA 2005-07-04 09:18:53 EDT
Added GenericTypeTest#test774.
Comment 3 Philipe Mulet CLA 2005-07-04 09:19:54 EDT
Tuned hiding check on TypeParameter, also ensured check is performed for generic
method type parameters.

Fixed
Comment 4 Maxime Daniel CLA 2005-08-09 07:48:00 EDT
Verified in 3.2 M1 with build I20050808-2000.
Comment 5 David Audel CLA 2005-09-26 09:52:59 EDT
Verified using M20050923-1430 for 3.1.1
Comment 6 Karl Kuhlmann CLA 2006-02-07 16:13:32 EST
I have the same warning when implementing List as follows:

public class ReadOnlyListProxy<T> extends AbstractProxy<List<T>> implements
    List<T> {
...
  public <T> T[] toArray(T[] a) {// The warning comes on this line
    return getData().toArray(a);
  }
}

getData is defined in AbstractProxy<T> as:

  protected T getData() {
    return theReference.get();
  }
All the other methods of List are fine. The signature of the offending method is identical to the one in List.
Comment 7 Philipe Mulet CLA 2006-02-07 21:24:51 EST
Right, but this one is a case where one definition of T (on method) is hiding the one from the enclosing type. So you cannot use the enclosing type parameter T within the method.
It is the intent of this warning to report such a case.

What do you see being wrong here ?
Comment 8 Karl Kuhlmann CLA 2006-02-10 21:29:54 EST
I guess I expect the signature of my implemenation of List<E> to be the same as the interface. In fact any changes I made to it just gave an error that I was not implementing the method. This signature is just what I got when I asked Eclipse to implement the method. Also the method works fine. How could the declaration be changed to remove the warning?
Comment 9 Philipe Mulet CLA 2006-02-13 04:15:45 EST
Simply rename the type parameter on the method to not collide:

  public <U> U[] toArray(U[] a) {// The warning comes on this line
    return getData().toArray(a);
  }

note that interface List<E> defines <T> toArray (observe non conflicting type parameter names).
Comment 10 Philipe Mulet CLA 2006-02-13 04:20:32 EST
Now you have a point. The tooling shouldn't generate a method signature which exposes this warning (it should perform substitution for you).
Comment 11 Philipe Mulet CLA 2006-02-13 04:21:14 EST
David/Martin: whose bug is this ?
Comment 12 Martin Aeschlimann CLA 2006-02-13 04:39:50 EST
That's probably ours. Please file a new bug request.
Comment 13 David Audel CLA 2006-02-13 05:18:30 EST
We have a bug in JDT/Core because we compute a bad signature and a bad completion string in our proposal. But i believe that JDT/Text don't use our completion string. So i suspect a bug on both side.
Comment 14 David Audel CLA 2006-02-16 04:49:10 EST
I opened a new CodeAssist bug in JDT/Core for this problem (bug 128169).

I close this one because the original problem of this bug is fixed.

Comment 15 Karl Kuhlmann CLA 2006-02-16 15:21:27 EST
(In reply to comment #10)
> Now you have a point. The tooling shouldn't generate a method signature which
> exposes this warning (it should perform substitution for you).

Thanks for your help. Now I would like to get disconnected from this bug, but I can's see how.