This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
#!null in generic procedures
- From: Chris Dean <Chris dot Dean at sokitomi dot com>
- To: Kawa List <kawa at sources dot redhat dot com>
- Date: Mon, 07 Apr 2003 19:13:28 -0700
- Subject: #!null in generic procedures
If one uses #!null as an argument to a generic procedure, we will always
fail to find a correct matching procedure. Consider this definition:
(define plus10 (make-procedure foo: 33 name: 'Plus10
method: (lambda (x y) (+ x
(if (number? y) y 0)
10))
method: (lambda () 10)))
Then this call will fail with a "Argument to 'Plus10' has wrong type"
error:
(plus10 10 #!null)
A patch is below. I believe that this is the correct semantics of
isInstance since null can be coerced into any type. At worst, we have
an ambiguous match for the procedure signature.
Regards,
Chris Dean
Index: gnu/bytecode/Type.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/bytecode/Type.java,v
retrieving revision 1.34
diff -u -r1.34 Type.java
--- gnu/bytecode/Type.java 18 Nov 2001 00:41:50 -0000 1.34
+++ gnu/bytecode/Type.java 8 Apr 2003 01:45:43 -0000
@@ -281,6 +281,8 @@
public boolean isInstance (Object obj)
{
+ if (obj == null)
+ return true;
return getReflectClass().isInstance(obj);
}
Index: testsuite/misc-test.scm
===================================================================
RCS file: /cvs/kawa/kawa/testsuite/misc-test.scm,v
retrieving revision 1.31
diff -u -r1.31 misc-test.scm
--- testsuite/misc-test.scm 20 Nov 2002 21:40:30 -0000 1.31
+++ testsuite/misc-test.scm 8 Apr 2003 01:45:43 -0000
@@ -1,4 +1,4 @@
-(test-init "Miscellaneous" 103)
+(test-init "Miscellaneous" 104)
;;; DSSSL spec example 11
(test '(3 4 5 6) (lambda x x) 3 4 5 6)
@@ -408,10 +408,13 @@
test-read-split)
(define plus10 (make-procedure foo: 33 name: 'Plus10
- method: (lambda (x y) (+ x y 10))
+ method: (lambda (x y) (+ x
+ (if (number? y) y 0)
+ 10))
method: (lambda () 10)))
(test 50 plus10 30 10)
(test 10 plus10)
+(test 20 plus10 10 #!null)
;;(test 10 'plus10-error
;; (try-catch (plus10 3) (ex <java.lang.Exception> "error")))
(test 33 procedure-property plus10 'foo)