Bug 60563 - [1.5] VerifyError when using generics and arrays
Summary: [1.5] VerifyError when using generics and arrays
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-30 09:11 EDT by Michael Forster CLA
Modified: 2005-01-11 11:02 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Forster CLA 2004-04-30 09:11:46 EDT
The following code:

    interface A<T> {
        T[] m1(T x);                          
    }
    class B { 
        void m2(A<B> x) { 
            m3(x.m1(new B())); 
        }
        void m3(B[] x) {
        }                    
    }
 
compiles but gives this Exception

    java.lang.VerifyError: (class: B, method: m2 signature: (LA;)V)
        Incompatible argument to function

when executed. I am using Eclipse I20040428 with Cheetah04.
Comment 1 Olivier Thomann CLA 2004-04-30 10:33:20 EDT
Here is the bytecodes we produce using latest:
  void m2(A x);
     0  aload_0
     1  aload_1
     2  new #2 X
     5  dup
     6  invokespecial #18 <Method X.<init>()V>
     9  invokeinterface [nargs : 2] #24 <Interface method
A.m1(Ljava/lang/Object;)[Ljava/lang/Object;>
    14  invokevirtual #28 <Method X.m3([LX;)V>
    17  return

You can see that the invokeinterface method returns an array of java.lang.Object
and the invokevirtual expects an array of X on the stack.

javac produces:
  void m2(A arg);
     0  aload_0
     1  aload_1
     2  new #2 X
     5  dup
     6  invokespecial #3 <Method X.<init>()V>
     9  invokeinterface [nargs : 2] #4 <Interface method
A.m1(Ljava/lang/Object;)[Ljava/lang/Object;>
    14  checkcast #5 [LX;
    17  invokevirtual #6 <Method X.m3([LX;)V>
    20  return

The intermediate checkcast converts the array of java.lang.Object into an array
of X and then the invokevirtual call is fine.
Comment 2 Philipe Mulet CLA 2004-05-07 12:21:24 EDT
Our check for adding generic casts did only consider case where original 
return type was a variable. Array of variable (T[]) wasn't handled.

Added regression test: GenericTypeTest#test175. Also upgraded similarily all 
generic cast inserted: field, name, qualified name, ...

Fixed