This is the mail archive of the kawa@sourceware.org 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: nested functions and #!optional


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/


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