# New Ticket Created by  Colin Kuskie 
# Please include the string:  [perl #44979]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=44979 >


While developing a return statement for NQP, I came across
this error from TGE:

Nonlinear attribute: you have two or more ways to assign a value to the 
attribute 'post' on node type 'PAST::Op' with rule name '_PAST::Op_post' near 
grammar line 

There's no line number.  The error comes from code near line 253 in 
compilers/tge/TGE/Tree.pir.

    $P7 = getattribute rule, "line"
    print $P7
    print "\n"

Attached is a patch against NQP to duplicate this bug.

SVN rev: 20865
Platform: FC7/x86

To reproduce:

patch -p0 < tge_error.diff
cd languages/nqp
make
../../parrot nqp.pbc t/10-sub.t


Index: languages/nqp/t/10-sub.t
===================================================================
--- languages/nqp/t/10-sub.t	(revision 20865)
+++ languages/nqp/t/10-sub.t	(working copy)
@@ -1,6 +1,6 @@
 #!./parrot
 
-say('1..10');
+say('1..11');
 
 sub one ( ) {
     say("ok 1 # sub def and call");
@@ -67,3 +67,11 @@
     print("not ");
 }
 say("ok 10 # subroutines that operate on args do not affect the original arg outside the sub");
+
+sub giveBack () {
+    return(1);
+    my $retVal := 2;
+}
+
+my $trial := giveBack();
+ok( $trial == 1, 'Checking return statement #1');
Index: languages/nqp/src/Grammar/Actions.pir
===================================================================
--- languages/nqp/src/Grammar/Actions.pir	(revision 20865)
+++ languages/nqp/src/Grammar/Actions.pir	(working copy)
@@ -156,7 +156,25 @@
     .return (past)
 .end
 
+##    method return_statement($/) {
+##        my $past := PAST::Op.new($($<EXPR>),
+##                                 pasttype => $<sym>,
+##                                 node => $/);
+##        }
+##        return $past;
+.sub 'return_statement' :method
+    .param pmc match
+    .local pmc past
+    $P0 = match['EXPR']
+    $P0 = $P0.'get_scalar'()
+    $P2 = getclass 'PAST::Op'
+    #$S1 = match['sym']
+    $S1 = 'tailcall'
+    past = $P2.'new'($P0, 'pasttype'=>$S1, 'node'=>match)
+    .return (past)
+.end
 
+
 ##    method block($/, $key) {
 ##        our $?BLOCK, @?BLOCK;
 ##        if ($key ne 'close') {

Reply via email to