Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

`shift` requires parens when it doesn't need them #12

Closed
xfix opened this Issue Sep 25, 2012 · 3 comments

Comments

Projects
None yet
2 participants

xfix commented Sep 25, 2012

use 5.010;
package Car;
sub new {
    my $class = shift;
    my $color = shift() // 'red';
    bless {color => $color}, $class;
}
sub color {
    shift()->{color}
}
package main;
my $car = Car->new;
say $car->color;

In this code, shift() could be replaced with shift - that works in Perl 5, but doesn't in Perlito.

Owner

fglock commented Sep 26, 2012

Confirmed - it looks like // is being parsed here as m//

Here is another related case:

$ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift / 2 '
Can't find string terminator '/' anywhere before EOF

2012/9/25 Êîíðàä Áîðîâñêè notifications@github.com

package Car;sub new {
my $class = shift;
my $color = shift() // 'red';
bless {color => $color}, $class;}sub color {
shift()->{color}}package main;my $car = Car->new;say $car->color;

In this code, shift() could be replaced with shift - that works in Perl
5, but doesn't in Perlito.


Reply to this email directly or view it on GitHubhttps://github.com/fglock/Perlito/issues/12.

xfix commented Sep 26, 2012

glitchmr@strawberry ~> perl -e 'shift / 2'
Warning: Use of "shift" without parentheses is ambiguous at -e line 1.
Search pattern not terminated at -e line 1.

shift / 2 should do that. Apparently it only affects // operator - it seems that it's always function that takes one argument unless the operator following shift is // (probably to improve DWIM) or something that simply cannot be prefix or term.

Owner

fglock commented Sep 27, 2012

Fixed; I've also updated
http://perlcabal.org/~fglock/perlito5.html

commit 7cdd110
Author: Flavio S. Glock fglock@gmail.com
Date: Thu Sep 27 14:19:07 2012 +0200

Perlito5 - parser - fix defined-or vs. match

Note: "make test" in Perlito is currently broken, because I'm adding more
tests. The "old" tests still pass.

thanks for testing!

2012/9/26 Êîíðàä Áîðîâñêè notifications@github.com

glitchmr@strawberry ~> perl -e 'shift / 2'
Warning: Use of "shift" without parentheses is ambiguous at -e line 1.
Search pattern not terminated at -e line 1.

shift / 2 should do that. Apperently it only affects // operator - it
seems that it's always function that takes one argument unless the operator
following shift is // (probably to improve DWIM) or something that simply
cannot be prefix or term.


Reply to this email directly or view it on GitHubhttps://github.com/fglock/Perlito/issues/12#issuecomment-8901058.

@fglock fglock closed this Mar 14, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment