Community
Participate
Working Groups
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.
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.
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