Subtyping for Array Annotations Now Working

I’m creating more and more tests for annotations with subtyping, and while most of it seems to work, I ran into one very important problem: Right now, my arrays do not support polymorphism yet. Consider the following:

@interface TopLevel { }
@interface Leaf extends TopLevel {
String value();
}
@interface Interior extends TopLevel {
TopLevel[] value();
}

@Interior({@Leaf("foo"),
@Interior({@Leaf("bar"),@Leaf("fee")}),
@Leaf("fum")})
class Something { ... }

I definitely want polymorphic arrays. In the example above, the @Interior declares an array of @TopLevel interfaces, but since @Interior and @Leaf are both subclasses of @TopLevel, I should be able to store them in the array as well.

The type checker and compilers don’t have a problem with this, and everything gets encoded correctly in the class file, but my runtime library has a bug: It creates an array of type TopLevel, which is correct, but then also imposes the type TopLevel for all its members! That means all members get “sliced” down to type TopLevel, so they don’t have any of their additional members present.

I have to use the type from the array declaration and use it to create the array. Then I have to use the type of each annotation for the annotation instance. Unfortunately, this information isn’t conveniently present. But I’ll work it out.

Update

I just fixed the problem with subtyping in arrays as described above.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in xajavac. Bookmark the permalink.

Leave a Reply