This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: java.lang.VerifyError for keyword with type


Chris Dean wrote:

Looks like we can generate invalid code for procedures that have
keywords. In the case where we specify the type of the keyword
parameter we get this error when loading:


<skipped>

+
+(define (proc-with-keywords x #!key (y :: <int> 1))
+ (list x y))
+


The problem is that the following code is produced by kawa:

   Object object
       = Keyword.searchForKeyword(argsArray, 0, Lit0, /*TYPE_ERROR*/ 1);
   int i;
   try {
       i = ((Number) object).intValue();
   } catch (ClassCastException classcastexception) {
       throw WrongType.make(classcastexception, "proc-with-keywords", 1);
   }
   int y = i;

so, as you may see, the default value is passed to Keyword.searchForKeyword, and it
must be Java object, not a Java primitive. The keyword arguments are passed as Object[], so all values are passed
also as Java objects.


So, until this bug is patched, use the following variant:

(define (proc-with-keywords1 x #!key y)
 (let((y :: <int> (or y 1)))
   (list x y)))

This variant compiles into correct (and more adequate) bytecode:

public static Object procWithKeywords1$V(Object x, Object[] argsArray) {
   Object y = Keyword.searchForKeyword(argsArray, 0, Lit0, Boolean.FALSE);
   Object GS$Dt1 = y;
   int y_0_ = GS$Dt1 != Boolean.FALSE ? ((Number) GS$Dt1).intValue() : 1;

Regards,
Vladimir


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]