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

Assigning to instance hashes,arrays fails #205

Closed
p6rt opened this issue Jul 30, 2008 · 4 comments
Closed

Assigning to instance hashes,arrays fails #205

p6rt opened this issue Jul 30, 2008 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Jul 30, 2008

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

Searchable as RT57422$

@p6rt
Copy link
Author

p6rt commented Jul 30, 2008

From johan.viklund@ebc.uu.se

On rakudo (rev. 29869) this fails with message "get_pmc_keyed() not
implemented in class 'Undef'"

class Foo {
  has %.bar is rw;
  method set_bar {
  %.bar<a> = 'baz';
  }
}
my $foo = Foo.new;
$foo.set_bar();

Initializing %.bar to () solves this particular problem, but another
one appears. Shown below

class Foo {
  has %.bar is rw;
  method set_bar {
  %.bar = ();
  %.bar<a> = 'baz';
  }
}
my $foo = Foo.new;
$foo.set_bar();
my %s = $foo.bar; # <- HERE BUG APPEARS

Gives this error​: "Odd number of elements found where hash expected"

And the workaround for this is to declare set_bar like this

method set_bar {
  my %bar_temp;
  %bar_temp<a> = 'baz';
  %.bar = %bar_temp;
}

For arrays​:

class Foo {
  has @​.bar is rw;
  method set_bar {
  @​.bar.push('baz');
  }
}

Gives "Method 'push' not found for invocant of class 'Undef'"

Similar workaround as for hash (eg. initialize it first).

--
Johan Viklund

@p6rt
Copy link
Author

p6rt commented Aug 7, 2008

From @jnthn

Hi,

As of r30090, the following​:

--
class Foo {
  has %.bar is rw;
  method set_bar {
  %.bar<a> = 'baz';
  }
}
my $foo = Foo.new;
$foo.set_bar();
my %s = $foo.bar;
say %s<a>;
--

Now prints "baz". Also this​:

--
class Bar {
  has @​.bar is rw;
  method set_bar {
  @​.bar[0] = 100;
  @​.bar[1] = 200;
  }
}
my $bar = Bar.new;
$bar.set_bar();
my @​t = $bar.bar;
say @​t[0];
say @​t[1];
--

Prints 100, then 200.

Thanks for reporting!

Jonathan

@p6rt
Copy link
Author

p6rt commented Aug 7, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 7, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Aug 7, 2008
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