On 02/02/2012 06:42 AM, Damian Conway wrote:
> S12 has an example that explicitly contradicts this constraint that 
> constructor
> args have to be public attribute names:
> 
>     submethod BUILD ($arg) {
>         $.attr = $arg;
>     }

That example is certainly a fossil.

In BUILD, the object isn't yet fully constructed, and thus using $.attr
(which is really a virtual method call in disguise) is wrong. STD and
niecza already catch that at compile time, and I'm currently trying to
make rakudo catch it too (branch 'has-self' on github).

More to the point, objects are constructed by .new calling .bless, which
in turn calls BUILDALL which finally calls BUILD. Since .bless only
takes named arguments (besides the candidate to be blessed), how could
BUILDALL know how to call BUILD with positional arguments?

Finally Rakudo, Niecza and Pugs all agree that the default .new and thus
.BUILD only take named arguments, and while that's not authoritative, it
is a strong indicator that the example above contradicts the compiler
writer's understanding of object initialization system.

Cheers,
Moritz

Reply via email to