On 09/28/2015 07:16 PM, mt1957 wrote:

False alarm, had a typing error in the code so, mea culpa poli :-[ .


Hi

Below a set of tests where all object creates are done well except for the last one using a sub or method returning the created object.


class X {
  has Str $.a;
}

my X $x .= new(a => 'abc');
say "\$x = {$x.perl}";

$x .= new(:a('abc'));
say "\$x = {$x.perl}";

$x .= new :a('abc');
say "\$x = {$x.perl}";

$x .= new :a<abc>;
say "\$x = {$x.perl}";

class X::Y {
  has Str $.a;
  has Str $.b;
}

my  $y = X::Y.new(
  a => 'abc',
  b => 'def'
);
say "\$y = {$y.perl}";

$y .= new( :a('abc'), :b('def'));
say "\$y = {$y.perl}";

$y .= new :a('abc') :b('def');
say "\$y = {$y.perl}";

$y .= new :a<abc> :b<def>;
say "\$y = {$y.perl}";



my X::Y $z = xy( <pqr stu>);
say "\$z = {$z.perl}";

sub xy ( Str $s1, Str $s2 --> X::Y ) {
  return X::Y.new(
    a => 'abc',
    b => 'def'
  );
}


The output and error returned is

$x = X.new(a => "abc")
$x = X.new(a => "abc")
$x = X.new(a => "abc")
$x = X.new(a => "abc")
$y = X::Y.new(a => "abc", b => "def")
$y = X::Y.new(a => "abc", b => "def")
$y = X::Y.new(a => "abc", b => "def")
$y = X::Y.new(a => "abc", b => "def")
Too few positionals passed; expected 2 arguments but got 1
  in sub xy at named-parameters.pl6:46
  in block <unit> at named-parameters.pl6:43


I have to explicitly rewrite it into one of the colon forms (';')

my  $y = X::Y.new(
  :a('abc'),
  :b('def')
);

Greets,
M

Reply via email to