[chuck-users] Bad return signature in pre-constructor leads to null instance

Robert Poor rdpoor at gmail.com
Thu Mar 12 15:51:34 EDT 2009


On 12 Mar 2009, at 06:54, Kassen wrote:

> ...Part of the problem is that it's not clear ChucK could know a  
> function will always return [a value] [discussion on the difficulty  
> of data flow analysis, etc...]

I agree that "it is an error" to declare that a function return a  
value and then not execute a return statement in the course of  
execution.  I even think it's reasonable to be C++ like and return a  
null (for a reference) or a 0 (for a number).

But that misses the point: it is NOT reasonable behavior for a null  
return value for a pre-constructor to cause the constructor itself to  
return null (unless that's documented behavior?!?).  Consider this:
============
public class FanOfKas {
	pre_constructor();

	public int pre_constructor() {
		return 42;
	}
}

FanOfKas we_like_kas;
<<< "we_like_kas =", we_like_kas >>>;
==============
Would anyone would claim that we_like_kas should be set to the integer  
42 rather than an instance of WeLikeKas?

- Rob



More information about the chuck-users mailing list