Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd issue with chained assignments and reference to array #4323

Closed
p6rt opened this issue Jun 14, 2015 · 8 comments
Closed

Odd issue with chained assignments and reference to array #4323

p6rt opened this issue Jun 14, 2015 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Jun 14, 2015

Migrated from rt.perl.org#125407 (status was 'resolved')

Searchable as RT125407$

@p6rt
Copy link
Author

p6rt commented Dec 5, 2013

From @hoelzro

There's a bug such that the following doesn't work as expected​:

  my $value = @​!values[0] = @​!values.pop;

-Rob

@p6rt
Copy link
Author

p6rt commented Dec 5, 2013

From @hoelzro

use v6;
use Test;

plan 1;

class BinaryHeap {
  has @​!values = (84, 85);

  method push($value) {
  fail 'I should never be called!';
  # commenting this line out fixes the problem (note how this method is never called?!?!)
  @​!values[0] = 1;
  }

  method pop {
  my $result = @​!values[0];

  if @​!values == 1 {
  @​!values.pop;
  } else {
  # changing this line...
  my $value = @​!values[0] = @​!values.pop;
  # ...to this fixes the problem
  #my $value = @​!values.pop;
  #@​!values[0] = $value;
  is $value, @​!values[0], '$value and @​!values[0] should be equal';
  }
  $result
  }
}

my BinaryHeap $heap .= new;
$heap.pop;
$heap.pop;

@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From @usev6

I wouldn't be surprised if this is the same problem as in ticket 80614 (https://rt-archive.perl.org/perl6/Ticket/Display.html?id=80614). There also doing something seemingly unrelated changes the behaviour of the chained assignment.

@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 14, 2015

From @hoelzro

With this bug, it seems that the following chained assignment​:

  my $value = @​values[0] = @​values.pop;

is generated using left-associativity instead of right-associativity.

@p6rt
Copy link
Author

p6rt commented Jun 14, 2015

From @hoelzro

use v6;
use Test;

plan 1;

my @​values = 84, 85;

if False { # note how this never runs
  my @​ref;
  @​ref[0] = 1; # commenting out this line, however, fixes the problem
}

# changing this line...
my $value = @​values[0] = @​values.pop;
# ...to these two fixes the problem
#my $value = @​values.pop;
#@​values[0] = $value;

is $value, @​values[0], '$value and @​values[0] should be equal';

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @hoelzro

On 2015-06-14 08​:21​:39, rob@​hoelz.ro wrote​:

With this bug, it seems that the following chained assignment​:

my $value = @​values\[0\] = @​values\.pop;

is generated using left-associativity instead of right-associativity.

Alright, I managed to figure out the problem last night. The issue is that the operator precedence table from HLL​::Grammar (used for both Grammar.O and Grammar.EXPR) has a hash of hashes, the values of which specify things like precedence and associativity. For example, the hash contains something like the following for the key '%list_assignment'​:

  { :prec<i=>, :assoc<right>, :sub<e=> }

The 'sub' key is the...umm, key here. After handling some things with %inO<prec> in HLL​::Grammar.EXPR, %inO<sub> is assigned to %inO<prec> - changing the precedence of list assignment from 'i=' to 'e=' *globally*.

Changing HLL​::Grammar to create a copy of the shared precedence hash fixes the problem; however, it also causes other, more essential features, like signatures and list assignment (but interestingly enough, not list initialization!) to fail in spectacular ways.

@p6rt p6rt closed this as completed Jun 17, 2015
@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

@hoelzro - Status changed from 'new' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant