Bug 85303 - [1.5] wrong declaring class for invokevirtual call
Summary: [1.5] wrong declaring class for invokevirtual call
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 85304 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-02-15 13:18 EST by Olivier Thomann CLA
Modified: 2005-03-31 08:48 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 Olivier Thomann CLA 2005-02-15 13:18:26 EST
In GenericTypeTest.test103, we changed the declaring class to solve a
VerifyError problem. I think we should generate a checkcast instead.

public class X <T extends AX> {
    T t;
    X(T t){
        this.t = t;
    }
    public static void main(String[] args) {
        X<BX<String>> x = new X<BX<String>>(new BX<String>());
		x.t.foo("SUCC");
		x.t.bar("ESS");
	}
}

class AX<P> {
   void foo(P p) { 
		System.out.print(p);
   }
}

class BX<Q> extends AX<Q> {
   void bar(Q q) { 
		System.out.println(q);
   }
}

We generate:
     0  new X [2]
     3  dup
     4  new BX [27]
     7  dup
     8  invokespecial BX.<init>()V [28]
    11  invokespecial X.<init>(LAX;)V [30]
    14  astore_1 [x]
    15  aload_1 [x]
    16  getfield X.t LAX; [17]
    19  ldc <String "SUCC"> [32]
    21  invokevirtual AX.foo(Ljava/lang/Object;)V [38]
    24  aload_1 [x]
    25  getfield X.t LAX; [17]
    28  checkcast BX [27]
    31  ldc <String "ESS"> [40]
    33  invokevirtual BX.bar(Ljava/lang/Object;)V [43]
    36  return

The lines:
    16  getfield X.t LAX; [17]
    19  ldc <String "SUCC"> [32]
    21  invokevirtual AX.foo(Ljava/lang/Object;)V [38]

are wrong. We should not change the declaring class to be AX. It should be BX.

We should generate something like this:
     0  new X [2]
     3  dup
     4  new BX [27]
     7  dup
     8  invokespecial BX.<init>()V [28]
    11  invokespecial X.<init>(LAX;)V [30]
    14  astore_1 [x]
    15  aload_1 [x]
    16  getfield X.t LAX; [17]
    19  checkcast BX [27]
    21  ldc <String "SUCC"> [32]
        invokevirtual BX.foo(Ljava/lang/Object;)V [36]
        aload_1 [x]
        getfield X.t LAX; [17]
        checkcast BX [27]
        ldc <String "ESS"> [38]
        invokevirtual BX.bar(Ljava/lang/Object;)V [41]
        return
Comment 1 Philipe Mulet CLA 2005-02-16 06:59:01 EST
*** Bug 85304 has been marked as a duplicate of this bug. ***
Comment 2 Philipe Mulet CLA 2005-02-16 16:02:54 EST
Tuned GenericTypeTest#test103.
Added GenericTypeTest#test501-505.
Fixed
Comment 3 Philipe Mulet CLA 2005-02-16 16:06:18 EST
Problem was due to special handling for extra bounds which did incorrectly fool
generic cast insertions.

Handling for extra bounds deals with code like:
<? extends Object&IFoo>.foo() --> needs to checkcast to IFoo

also discovered it did not perform well for field references (field, simple,
qualified)
Comment 4 David Audel CLA 2005-03-31 08:48:52 EST
Verified in I20050330-0500