Skip Menu |

This queue is for tickets about the Dios CPAN distribution.

Report information
The Basics
Id: 127579
Status: open
Priority: 0/
Queue: Dios

People
Owner: DCONWAY [...] cpan.org
Requestors: felix.ostmann [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.002011
Fixed in: (no value)



Subject: submethod BUILD with parameters and name conflict has strange behavior
Hello again, attached a failing test for BUILD with named parameters. I am not sure about the correct behavior for Test5, but undef for $foo in BUILD is in my option not an option. And Test6 should work as expected when using labeled parameters.
Subject: build_with_parameters.t
use warnings; use strict; use Dios; use Test::More; class Test1 { has $.foo = 1; submethod BUILD { ::is($foo, 1, 'Test1 - $foo from attribute after default BUILD for $foo'); } } class Test2 { has $.foo = 1; submethod BUILD { ::is($foo, 2, 'Test2 - $foo from parameter after default BUILD for $foo'); } } class Test3 { has $.foo = 1; submethod BUILD (:$bar) { ::is($foo, 1, 'Test3 - $foo from attribute after default BUILD for $foo'); } } class Test4 { has $.foo = 1; submethod BUILD (:$bar) { ::is($foo, 2, 'Test4 - $foo from parameter after default BUILD for $foo'); } } class Test5 { has $.foo = 1; submethod BUILD (:$foo) { # what should happen here? attribute or parameter?! ::is($foo, 2, 'Test5 - $foo from parameter while BUILD for $foo'); } } class Test6 { has $.foo = 1; submethod BUILD (:foo($newfoo)) { ::is($newfoo, 2, 'Test6 - $newfoo from parameter while BUILD for $foo'); ::is($foo, 1, 'Test6 - $foo from attribute while BUILD for $foo'); # $foo should not be set per default BUILD for $foo $foo = $newfoo; } } ::is 'Test1'->new( )->get_foo(), 1 => 'Test2 - $foo still from attribute'; ::is 'Test2'->new(foo => 2 )->get_foo(), 2 => 'Test2 - $foo from parameter'; ::is 'Test3'->new( bar => 2)->get_foo(), 1 => 'Test3 - $foo still from attribute'; ::is 'Test4'->new(foo => 2, bar => 2)->get_foo(), 2 => 'Test4 - $foo from parameter'; ::is 'Test5'->new(foo => 2 )->get_foo(), 2 => 'Test5 - $foo from parameter'; ::is 'Test6'->new(foo => 2 )->get_foo(), 2 => 'Test6 - $foo from parameter'; done_testing();
Subject: Re: [rt.cpan.org #127579] submethod BUILD with parameters and name conflict has strange behavior
Date: Wed, 7 Nov 2018 07:50:51 +0000
To: bug-Dios [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Thanks, Felix. I'm still tracking down this issue. Will update when I work out what's going on. Much appreciated! Damian