Wed 03 May 2006 10:01:02 PM UTC, original submission:
Here's a simple example from Chris Dean:
--------------------------------------------------
This Java class will not compile because the return value for getTime() is of the wrong type:
public class MyJavaClass extends java.util.Date {
public String getTime() {
return( "a string" );
}
}
MyJavaClass.java:2: getTime() in MyJavaClass cannot override getTime() in java.util.Date; attempting to use incompatible return type
found : java.lang.String
required: long
public String getTime() {
^
1 error
However, this Kawa code will compile and produce the wrong class:
(define-simple-class <MySchemeClass> (<java.util.Date>)
((getTime)
"a string"))
--------------------------------------------------
Attached is a more complicated example based on a problem encountered by our developers. The part that's at first surprising is that which method gets called depends on how the function being returned has been defined (see base-lambda vs. base-fn).
I think it boils down to the fact that in the <A>/<B> example, the signatures of A.m0 and B.m0 vary in return type. The results mentioned in the comments only apply to compiled code.
Maybe there's another problem being exposed by this example, but I think if the compiler issued an error when it encounters an override with incompatible return types, it would help narrow down these problems much more quickly.
This isn't a show-stopper. It crops up every once in a while and is difficult to debug, and it would be nice if some kind of fix worked its way into Kawa.
|