classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Re: [commit-cp] [bug #12699] TreeSet & PriorityQueue in gen


From: Andrew John Hughes
Subject: [cp-patches] Re: [commit-cp] [bug #12699] TreeSet & PriorityQueue in generics_branch cannot be compiled with sun's javac.
Date: Sat, 16 Apr 2005 12:37:45 +0100

On Sat, 2005-04-16 at 05:28 +0000, Ewout Prangsma wrote:
> URL:
>   <http://savannah.gnu.org/bugs/?func=detailitem&item_id=12699>
> 
>                  Summary: TreeSet & PriorityQueue in generics_branch cannot
> be compiled with sun's javac.
>                  Project: classpath
>             Submitted by: epr
>             Submitted on: Sat 04/16/2005 at 05:28
>                 Category: classpath
>                 Severity: 3 - Normal
>                   Status: None
>                  Privacy: Public
>              Assigned to: None
>              Open/Closed: Open
>         Platform Version: None
> 
>     _______________________________________________________
> 
> Details:
> 
> Compiling it with Eclipse 3.1M6 is ok, sun's javac give invalid type errors.
> 
> The patches are here:
> 
> ===================================================================
>   RCS file:
> /cvsroot/jnode/jnode/core/src/classpath/5.0/java/util/TreeSet.java,v
>   retrieving revision 1.1
>   retrieving revision 1.2
>   diff -u -r1.1 -r1.2
>   --- TreeSet.java    15 Apr 2005 07:46:57 -0000      1.1
>   +++ TreeSet.java    15 Apr 2005 18:52:58 -0000      1.2
>   @@ -151,7 +151,7 @@
>      {
>        Iterator<T> itr;
>    
>   -    map = new TreeMap<T, String>(sortedSet.comparator());
>   +    map = new TreeMap<T, String>((Comparator<? super
> T>)sortedSet.comparator());
>        itr = ((SortedSet<T>) sortedSet).iterator();
>        ((TreeMap<T, String>) map).putKeysLinear(itr, sortedSet.size());
>      }
>   
>   
>   
>   1.2       +8 -4     
> jnode/core/src/classpath/5.0/java/util/PriorityQueue.java
>   
>   Index: PriorityQueue.java
>   ===================================================================
>   RCS file:
> /cvsroot/jnode/jnode/core/src/classpath/5.0/java/util/PriorityQueue.java,v
>   retrieving revision 1.1
>   retrieving revision 1.2
>   diff -u -r1.1 -r1.2
>   --- PriorityQueue.java      15 Apr 2005 07:46:57 -0000      1.1
>   +++ PriorityQueue.java      15 Apr 2005 18:52:58 -0000      1.2
>   @@ -76,7 +76,8 @@
>        if (c instanceof SortedSet)
>          {
>       SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
>   -   this.comparator = ss.comparator();
>   +    // @classpath-bugfix Type mismatch using sun's compiler
>   +   this.comparator = (Comparator<? super E>)ss.comparator();
>       // We can insert the elements directly, since they are sorted.
>       int i = 0;
>       for (E val : ss)
>   @@ -89,7 +90,8 @@
>        else if (c instanceof PriorityQueue)
>          {
>       PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c;
>   -   this.comparator = pq.comparator();
>   +    // @classpath-bugfix Type mismatch on sun's compiler
>   +   this.comparator = (Comparator<? super E>)pq.comparator();
>       // We can just copy the contents.
>       System.arraycopy(pq.storage, 0, storage, 0, pq.storage.length);
>          }
>   @@ -111,14 +113,16 @@
>    
>      public PriorityQueue(PriorityQueue<? extends E> c)
>      {
>   -    this(Math.max(1, (int) (1.1 * c.size())), c.comparator());
>   +      // @classpath-bugfix Type mismatch on sun's compiler
>   +    this(Math.max(1, (int) (1.1 * c.size())), (Comparator<? super
> E>)c.comparator());
>        // We can just copy the contents.
>        System.arraycopy(c.storage, 0, storage, 0, c.storage.length);
>      }
>    
>      public PriorityQueue(SortedSet<? extends E> c)
>      {
>   -    this(Math.max(1, (int) (1.1 * c.size())), c.comparator());
>   +      // @classpath-bugfix Type mismatch on sun's compiler
>   +    this(Math.max(1, (int) (1.1 * c.size())), (Comparator<? super
> E>)c.comparator());
>        // We can insert the elements directly, since they are sorted.
>        int i = 0;
>        for (E val : c)
>   
>   
> 
> 
> 
> 
> 
> 
>     _______________________________________________________
> 
> Reply to this item at:
> 
>   <http://savannah.gnu.org/bugs/?func=detailitem&item_id=12699>
> 
> _______________________________________________
>   Message sent via/by Savannah
>   http://savannah.gnu.org/
> 
> 
> 
> _______________________________________________
> Commit-classpath mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/commit-classpath
> 

I'm not sure if this is a slip-up in Sun's compiler or ecj.  I'm tempted
to go with the former.  The comparator has the type:

<? super E>

where E is <? extends E>, giving:

<? super ? extends E>

The spec. says that ? extends E contains E, so surely the compiler can
infer <? super E> from this.

The error from Sun is:

java/util/PriorityQueue.java:92: incompatible types
found   : java.util.Comparator<capture of ? super capture of ? extends
E>
required: java.util.Comparator<? super E>

I'm committing the attached patch, which fixes this without causing any
problems with the ecj build.  However, I'd be interested to know
people's thoughts on this.

Changelog:

2005-04-16  Andrew John Hughes  <address@hidden>

        * java/util/PriorityQueue.java:
        (PriorityQueue(Collection<? extends E>)): Added explicit cast
        for comparators.
        (PriorityQueue(PriorityQueue<? extends E>)): Likewise.
        (PriorityQueue(SortedSet<? extends E>)): Likewise.
        * java/util/TreeSet.java:
        (TreeSet(SortedSet<? extends T>)): Likewise.

        Reported by: Ewout Prangsma <address@hidden>

-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint)
attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

No software patents in Europe -- http://nosoftwarepatents.com

"Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn."
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]