nested functions and #!optional
Per Bothner
per@bothner.com
Sat Jul 28 07:06:00 GMT 2012
On 07/26/2012 09:06 AM, Chuah Teong Leong wrote:
> I've got a situation where it unexpectedly throws an exception which puzzled me.
>
> (define (func)
> (define (nested-func #!optional arg)
> (set! arg "any string"))
> (nested-func))
>
> (func)
>
> doing the above throws this
> java.lang.ClassCastException: java.lang.Boolean cannot be casted to
> java.lang.String
This is a bug in type-inference: Kawa infers the type of arg
to be boolean, because the setting of the initial value is the
only assignment it sees.
I seem to remember an existing bug report in Savannah
for a similar bug.
A work-around is add an explicit type specifier:
(define (func)
(define (nested-func #!optional (arg :: object))
(set! arg "any string"))
(nested-func))
Of course I would argue that assigning to a function
parameter is exceedingly poor style!
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list