Community
Participate
Working Groups
Strange error message when compiling static classes nested inside abstract when type parameters are present. This appears to be a new problem in the compiler. It's occuring for me with I20050426-1700. The error: "Cannot make a static reference to the type parameter IndexedIter", at "return new IndexedIter();" /* * Created on Apr 29, 2005 * */ package com.soletta.stream; import java.util.Iterator; abstract public class Isolate<T> implements Iterable<T> { final Iterable<T> source; protected Isolate(Iterable<T> source) { this.source = source; } public static class Indexed<OUT> { Iterable<OUT> source; final int from, to; protected Indexed(Iterable<OUT> source, int from, int to) { this.source = source; this.from = from; this.to = to; } public Iterator<OUT> iterator() { return new IndexedIter(); } class IndexedIter implements Iterator<OUT> { Iterator<OUT> src = source.iterator(); int n = from; int c = from; IndexedIter() { } private void drop() { while (n > 0 && src.hasNext()) { src.next(); n--; } } public boolean hasNext() { if (n > 0) drop(); return (to < 0 || c < to) && src.hasNext(); } public OUT next() { if (n > 0) drop(); if (to >= 0 && c >= to) { throw new IndexOutOfBoundsException(); } c++; return src.next(); } public void remove() { if (n > 0) drop(); if (to >= 0 && c >= to) { throw new IndexOutOfBoundsException(); } src.remove(); } } } }
Note that if the inner static class "Indexed" is moved into its own file, everything is fine (IndexedIter is then still an inner class for Indexed, but Indexed is no longer "inside" the outer static class.
Reproduced
I would be happy to share the source for the entire library this snippet comes from with the Eclipse compiler team. It beats up the compiler pretty thoroughly, as it uses a lot of this kind of thing, trying to do a kind of virtual typing for stream composition. I end up having to do quite a few Clean operations on Eclipse projects while I'm working with the code and it is in an uncompilable state, although once the code is syntactically correct I usually don't have to resort to clean. public interface Stream<IN, OUT, OP extends Stream<?, OUT, OP>> extends Iterable<OUT>, StreamInternal<IN, OUT, OP>, Begin<IN, OP> { /** Dump the contents of the stream to the display, with a * header on each element. This is a pull-through operation, * causing contributing streams to be pulled. * * @return */ OP dump(String header); ....
Sounds a neat testcase. FYI, we addressed today a problem in our incremental compiler which wouldn't notice type parameter changes (by accident) until now. These should now be watched, and consequently you shouldn't need to trigger clean build any longer. Now, if you still find some issues, please enter a separate defect.
Added GenericTypeTest#test635
Fixed by moving the updating of insideStaticContext flag after member type lookup.
Maxime - pls try to get a hold on sample code mentionned in comment#3 to check whether issue can still be reproduced.
(In reply to comment #3) > I would be happy to share the source for the entire library this snippet comes > from with the Eclipse compiler team. Ross, we'd be more than interested. Could you please let us know your preferred way of doing so?
(In reply to comment #8) > (In reply to comment #3) > > I would be happy to share the source for the entire library this snippet > comes > > from with the Eclipse compiler team. > Ross, we'd be more than interested. Could you please let us know your preferred > way of doing so? Have sent email to Maxime with the library attached.
Got source tree, thx.
Verified in I20050510-0010