|
Does a constructor have to return this?
I would have sworn I read it somewhere in the book, but I couldn't find it. The only thing that comes close is on page 95 right before Figure 9.5: Therefore the type of a constructor must always be the name of the class to which it belongs.
The reason I ask is because I implemented my parser so it quits with an error message if the return type in the constructor's declaration doesn't match the class name, or if it doesn't return this. Parsing ExpressionLessSquare\Square.jack and ExpressionLessSquare\SquareGame.jack doesn't complete because they contain constructors that don't return this. If I change the code to return this my parser finishes without a problem, but then the Text Comparer throws a hissy fit.
If I disable this extra check, the files in ExpressionLessSquare pass, but it doesn't feel right. Besides, the constructors in Square and ArrayTest do return this like they should.
Does anyone have an opinion on this? (pun not intended ;)
|