On Fri, Dec 28, 2007 at 07:11:23PM -0800, chromatic wrote:
> On Friday 28 December 2007 16:16:55 Patrick R.Michaud wrote:
> 
> > Whenever a PAST::Op node gets a non-PAST child, PCT currently
> > throws a cryptic exception message like:
> >
> > Method 'named' not found for invocant of class 'Perl6::Grammar'
> >
> > A better exception message would be something like:
> >
> > Perl6::Grammar ("2") child of PAST::Op cannot be converted to POST.
> 
> How does this node "get" a non-PAST child?  Is there a single point at which 
> you add a child to a PAST::Op node?  (I'm pretty sure I know the answer, but 
> I'm not entirely sure.)

Yes, however, adding a non-PAST child to a PAST node isn't necessarily
an error.  The exception should probably be thrown at the point where
PAST::Compiler attempts to convert the (non-PAST) child to POST, not
at the point where the child is added to a PAST::Node.

The fix is easy enough to do -- just a small modification to the 
'post_children' method of PAST::Compiler (src/PAST/Compiler.pir)
to throw an exception when it sees a non-PAST child.  I simply entered 
the ticket as a placeholder so it's not forgotten.

Or, we could perform the check at the point of the 'push' or 'unshift'
method that adds nodes to a PAST child, with an optional :force
flag to allow non-PAST children to be added.

As to how it's possible for a non-PAST node to appear as a child,
it comes up when a transformation method inadvertently adds a match
object or constant to a PAST::Node instead of the ast (PAST) 
representation of the match object or constant.

Thanks!

Pm

Reply via email to