- changed status to resolved
WildcardSuperType has variable size zero
Issue #276
resolved
ExtendJ 8.1.0-27-gcd7effa Java SE 5
An expression that has a type like ? super Integer
will be treated as having size zero by ExtendJ. This can cause issues in generated bytecode. For example, when calling a method that returns type ? super X
, as in the following program:
// Test that executable bytecode is generated when discarding a method
// result from a method that returns some wildcard-super type.
// .result: EXEC_PASS
public class Test {
public static void main(String[] args) {
Container<? super Integer> con = new Container<Integer>(123);
for (int i = 0; i < 1; ++i) {
con.get();
}
}
}
class Container<T> {
private final T value;
public Container(T value) {
this.value = value;
}
T get() {
return value;
}
}
In this case, there should be a POP instruction after the call to con.get()
. However, ExtendJ does not generate a POP which causes a stack height mismatch when branching back to the start of the for-statement. This leads to a verification error when trying to run the compiled program:
[junit] [FAIL] runTest[run/generics/container_05](tests.extendj.TestJava7)
[junit] Error output files differ expected:<[]> but was:<[Exception in thread "main" java.lang.VerifyError: (class: Test, method: main signature: ([Ljava/lang/String;)V) Inconsistent stack height 1 != 0
[junit] at java.lang.Class.getDeclaredMethods0(Native Method)
[junit] at java.lang.Class.privateGetDeclaredMethods(Class.java:2575)
[junit] at java.lang.Class.getMethod0(Class.java:2816)
[junit] at java.lang.Class.getMethod(Class.java:1665)
[junit] at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:418)
[junit] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:410)]>
Comments (1)
-
reporter - Log in to comment
Fix error in TypeDecl.variableSize()
This changes TypeDecl.variableSize() to have the default value 1.
This fixes an error where some types that should have size 1 were treated as having size 0, which could lead to missing pop instructions (and other errors) in generated bytecode.
fixes
#276(bitbucket)→ <<cset 1cac6f166899>>