Forum Stats

  • 3,852,361 Users
  • 2,264,096 Discussions
  • 7,905,046 Comments

Discussions

bug in spec or compiler?

843793
843793 Member Posts: 41,732 Green Ribbon
edited Oct 1, 2002 1:32AM in Generics
Hello!

I have some problems with the jsr14 specification and the compiler implementation. I am not a native english speaker, but I think I can understand the specification correctly.

In the spec8.pdf document "Adding Generics to the Java Programming Language - Participant Draft Specification" on page 16 example 20: this should not compile but it does compile with jsr14 prototype 1.2 (javac 1.4.0_01)! Why? Anyone tried this?

In the same spec page 14: 6.1: "the erasure of a type variable is [...] if the bound consists of interface tyes only, the interface among the erasures of all interface types which has the least canonical name, using lexicographic ordering."
This sounds crazy, and the compiler does it different. It always uses the first parameter (following extends)! You can see this using "javap -c" on the bytecode. So, what�s right?

In the spec, page 3: "if a type parameter X has more than one bound, then it is a compiletime error to reference a member of an object whose declared type is X, unless that member is an accessible member of class java.lang.object"
Well, why is this an error? It compiles without any errors!

And another point: in the spec are examples of type variables with the "A implements I" syntax, which is not allowed. The compiler uses "extends" only. The example code is even on the same page (Page 3). Oh, oh!

Maybe I am wrong in some parts, and you can help me. (I cant believe, that I found three bugs in five hours) Any comments?

Comments

  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    There were no answers to my questions, yet. Here is some sample code to show my problems:
    In the spec8.pdf document "Adding Generics to the Java
    Programming Language - Participant Draft
    Specification" on page 16 example 20: this should not
    compile but it does compile with jsr14 prototype 1.2
    (javac 1.4.0_01)! Why? Anyone tried this?
    Here is the code:
    class C<A> { A id (A x) {} }
    interface I<A> { A id(A x); }
    // should not compile, but does compile!
    public class D extends C<String> implements I<Integer> {
    String id(String x) {}
    Integer id(Integer x) {}
    }
    In the same spec page 14: 6.1: "the erasure of a type
    variable is [...] if the bound consists of interface
    tyes only, the interface among the erasures of all
    interface types which has the least canonical name,
    using lexicographic ordering."
    This sounds crazy, and the compiler does it different.
    It always uses the first parameter (following
    extends)! You can see this using "javap -c" on the
    bytecode. So, what�s right?
    Here is the code:
    interface IA{ public void testA(); }
    interface IB{ public void testB(); }
    interface IC{ public void testC(); }
    public class Test<A extends IB & IA & IC>{
    public A value; // javap tells me, that value has type IB!
    }

    In the spec, page 3: "if a type parameter X has more
    than one bound, then it is a compiletime error to
    reference a member of an object whose declared type is
    X, unless that member is an accessible member of class
    java.lang.object"
    Well, why is this an error? It compiles without any
    errors!
    Here is the code:
    public class Test2<A extends IA & IB & IC>{
    private A value;
    public static void main(String[] args){
    value.testA(); // where is the problem
    value.testB(); // it works!
    }
    }

    And another point: in the spec are examples of type
    variables with the "A implements I" syntax, which is
    not allowed. The compiler uses "extends" only. The
    example code is even on the same page (Page 3). Oh,
    oh!
    Here is the code:
    class ReprChange<A implements ConvertibleTo<B>,
    B implements ConvertibleTo<A>> {....
    Maybe I am wrong in some parts, and you can help me.
    (I cant believe, that I found three bugs in five
    hours) Any comments?
    Again: is anyone here who can tell me what is right?
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    I'd go to the page http://developer.java.sun.com/developer/earlyAccess/adding_generics/ and submit your observations as comments.
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    I'd go to the page
    http://developer.java.sun.com/developer/earlyAccess/add
    ng_generics/ and submit your observations as comments.
    thanks for the tip. I got an answer in 3 hours. Here it is:
    In the spec8.pdf document "Adding Generics to the Java
    Programming Language - Participant Draft
    Specification" on page 16 example 20: this should not
    compile but it does compile with jsr14 prototype 1.2
    (javac 1.4.0_01)! Why?
    this is a compiler bug
    In the same spec page 14: 6.1: "the erasure of a type
    variable is [...] if the bound consists of interface
    tyes only, the interface among the erasures of all
    interface types which has the least canonical name,
    using lexicographic ordering."
    This sounds crazy, and the compiler does it different.
    It always uses the first parameter (following
    extends)! You can see this using "javap -c" on the
    bytecode. So, what�s right?
    the compiler
    In the spec, page 3: "if a type parameter X has more
    than one bound, then it is a compiletime error to
    reference a member of an object whose declared type is
    X, unless that member is an accessible member of class
    java.lang.object"
    Well, why is this an error? It compiles without any
    errors!
    compiler is right
    And another point: in the spec are examples of type
    variables with the "A implements I" syntax, which is
    not allowed. The compiler uses "extends" only. The
    example code is even on the same page (Page 3). Oh,
    oh!
    error in spec

    There will be a revised draft spec in the next few months.
This discussion has been closed.