Re: type checking in EUPHORIA
- Posted by mattlewis (admin) Sep 17, 2012
- 1237 views
Occasionally, while looking at software written in EUPHORIA I have seen a kind of programming error which a parser can catch.
I agree that the parser should be able to catch more datatype usage errors than it currently does. My take on this is that when the parser can know the datatype of both the source expression and the target of that expression, it should issue a warning if the datatypes are incompatible. This would be a parse-time warning and not a run-time warning. Conversely, if the parser does not absolutely know the datatypes at parse-time, then it should behave as it does now.
I would go further and throw an error. We do this already in some cases. Mostly when we end up inlining something, I think.
This extends beyond enumerated types to also include native types and user-defined types.
To enhance this behaviour, we may have to look at letting the parser know the expected datatype ofa funtion's return value. Currently, from the point of view of the parser, a function always returns an object.
-- example function somefunc(integer a)(sequence) ... return some_seq end function
Yes, this would be a nice enhancement. Maybe something like:
-- example function somefunc(integer a) as sequence ... return some_seq end function
I did something like this in ooeu in order to improve polymorphism.
Matt