This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: warnings when calling methods from Java interfaces, not classes
- From: Per Bothner <per at bothner dot com>
- To: "Hoehle, Joerg-Cyril" <Joerg-Cyril dot Hoehle at t-systems dot com>
- Cc: kawa at sources dot redhat dot com
- Date: Fri, 31 Oct 2003 09:53:26 -0800
- Subject: Re: warnings when calling methods from Java interfaces, not classes
- References: <9F8582E37B2EE5498E76392AEDDCD3FE0792FC3C@G8PQD.blf01.telekom.de>
Hoehle, Joerg-Cyril wrote:
The problem is that these methods come from interfaces, not classes, so a cast using (as <class.x> y) is of no help here.
Er, Kawa appears to be correct. If you transcribe this code to Java, it
would not compile. There is not getModulus or getPublicExponent in the
PublicKey interface.
E.g. Java.security is full of interfaces:
http://java.sun.com/j2se/1.4.2/docs/api/java/security/interfaces/RSAPublicKey.html
But your code doesn't use <java.security.interfaces.RSAPublicKey>, it
uses <java.security.PublicKey>. If we change the declaration of pubkey
to <java.security.interfaces.RSAPublicKey> two of the warnings go away.
The other warnings can be shut up using casts to <byte[]>, though of
course it is preferable if Kawa knows the types of bigint-n-bytes and
gen-pkcs1:
;;TODO KeyMod may have 129 bytes, need 128
(define (bigint-n-bytes n big :: <java.math.BigInteger>)
(invoke big 'toByteArray))
It's best to explicitly specify the return type as <byte[]>, though it
doesn't seem to make a difference in this case. I go back and forth on
whether Kawa should attempt to infer return types of functions and just
use <object> if it isn't declared. The problem is that until Kawa has
solid and consistent typechecking it's hard to specify under which
circumstances Kawa can infer a return type, and it is important that
this be consistent because it is wired into the Java method type.
If you declare bigint-n-bytes before rnd-pkcs1 and compile then as a
file, then Kawa knows the return type of bigint-n-bytes. (You can also
force them to be compiled together with a 'begin' form.)
I expect to do an overhaul of Kawa's type-checking and inference at some
point in order to implement correct static type-checking for Qexo. No
idea when that will happen.
It further seems that type declarations for variables are ignored by subsequent code in interactive mode.
It works when compiling as a module. Compiling with with -C produces no
warnings:
(define random-gen :: <java.security.SecureRandom>
(invoke-static <java.security.SecureRandom> 'getInstance "SHA1PRNG"))
(define (foo key-gen :: <java.security.KeyPairGenerator>)
(invoke key-gen 'initialize (as <int> 1024) random-gen))
I don't know why the cast of 1024 to <int> is needed. Probably Kawa
could be smarter here.
--
--Per Bothner
per@bothner.com http://per.bothner.com/