develooper Front page | perl.perl6.users | Postings from January 2019

Bad syntax check

Thread Next
ToddAndMargo via perl6-users
January 2, 2019 20:04
Bad syntax check
Message ID:
Dear Perl 6 Developers,

Fedora 29, x64
Xfce 4.13

$ perl6 -v
     This is Rakudo version 2018.11 built on MoarVM version
     2018.11 implementing Perl 6.d.

I am constantly improving (changing things) in my subs,
etc..  As such, the things I return often change.

Because of this, I have a found something I just do not like
in the checker (Perl6 -c xxx) and the run time compiler.

Here is a simplified sample code with the error in it:

<code RtnBooBoo.pl6>
#!/usr/bin/env perl6

sub AddThree( Int $a, Int $b, Int $c ) {
    my Int $d = $a + $b + $c;
    return $d;

my Int $X = 0;
my Int $Y = 0;

( $X, $Y ) = AddThree( 1, 2, 3 );
say "X = <$X>\tY = <$Y>";
</code RtnBooBoo.pl6>

The error is that the subroutine is only returning one
value and two are trying to be read.

And the checker passes it!

     $ perl6 -c RtnBooBoo.pl6
     Syntax OK

No, it is not okay.  The sub and the caller do not match up!

If you run the flawed code, you get:

     $ RtnBooBoo.pl6
     Use of uninitialized value of type Int in string context.
     Methods .^name, .perl, .gist, or .say can be used to stringify
     it to something meaningful.  in block <unit> at ./RtnBooBoo.pl6
     line 12

     X = <6>	Y = <>

Which is a bizarre warning (it does not stop on this error).  And
it is also not the error.  The error was that the return line's
returned variables and the caller do not match up.  Not an
uninitialized value.

If you send too few variables to a sub, you get the finger shaken
at you.  The return should also have the same checking capability.

Would you guys please consider improving the checker and the compiler?

Many thanks,

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About