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: Confusing error message


On 04/21/2011 03:49 PM, Charles Turner wrote:
On 17/04/2011 08:04, Per Bothner wrote:


Type checking seems to be a mixed bag in Kawa, most of the time the type errors seem to emanate from a ClassCastException, which seems quite elegant. I'll have to look into why cdr doesn't do it like this, but when I find out why, would it be okay to try and make it use the ClassCastException as well?

Well, WrongType has more structure, which is preferable. Perhaps it might make sense to have WrongType extend ClassCastException.


I think so.

I had a look at this today, but the Kawa source got the better of me. For some stupid reason, I figured that the ClassCastException would be thrown with a custom detail string, how wrong I was. For the contrived example of evaluating (cddr '()) [one that throws ClassCastExceptions currently] the exception is thrown from ModuleMethod.apply1 in the expression,

return module.apply1(this, arg1);

I was looking at this in a debugger and noticed that module is of type
"lists" which from a quick inspection doesn't have an apply1 method
(it's a scheme file), I'm struggling to understand how this is working
at all!

If it was easy, anyone could do it.


The apply1 is the one defined in ModuleBody.  lists.scm is compiled to a
class lists - which extends ModuleBody.

The apply1 method is generated by Compilation#generateApplyMethodsWithoutContext.

A ClassCastException is caught and turned into a WrongType by the
CheckedTarget#emitCheckedCoerce.

This is pretty hairy stuff, since it depends on understanding bytecode
and how it is generated.  If you figure that out, you'll be in rare
company!
--
	--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]