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

attributive parameters alter object during any bind, not just invoke #4332

Open
p6rt opened this issue Jun 19, 2015 · 4 comments
Open

attributive parameters alter object during any bind, not just invoke #4332

p6rt opened this issue Jun 19, 2015 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 19, 2015

Migrated from rt.perl.org#125437 (status was 'new')

Searchable as RT125437$

@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

From @skids

# Attributive parameters can load themselves into objects during
# seemingly innocent smartmatches, and probably other places where
# is_bindable semantics are intended.
perl6 -e 'class a { has $.a; method foo { say so (self,2) ~~ :(\self​: $!a); self.a.say } }; a.new.foo()'
True
2

#...like multidispatch tests
$ for i in 1 2 3 4 5; do perl6 -e 'my $*r; class A { has $.a = 4; multi method foo (A $b (​:$!a), Int $c where { $*r //= Bool.pick }) { 42.say }; multi method foo (A $b, Int $c) { self.a.say } }; my A $a .= new; my A $b .= new(​:a(2)); $a.foo($b,1);' ; done
2
2
42
2
42
# (above, $a.a should only be 2 when 42 is printed, should otherwise be 4.)

@p6rt
Copy link
Author

p6rt commented Aug 3, 2015

From @skids

Please also see the conversation at​:

http://irclog.perlgeek.de/perl6/2015-08-02#i_10992867

...when deciding how to fix this one.

@p6rt
Copy link
Author

p6rt commented Sep 20, 2015

From @skids

More investigation, done while trying to get the desired behavior mentioned
in the IRC conversation​:

It appears that just mentioning an attribute in a BUILD submethod is enough
to prevent it from being assigned its default after the custom BUILD is run;
you don't have to actually assign to it​:

(12​:58​:54 PM) skids​: m​: class A { has $.a = 42.say; submethod BUILD { } }.new.a.perl.say;
(12​:58​:55 PM) camelia​: rakudo-moar 97e47a​: OUTPUT«42␤Bool​::True␤»
(12​:59​:09 PM) skids​: m​: class A { has $.a = 42.say; submethod BUILD { $!a; } }.new.a.perl.say;
(12​:59​:10 PM) camelia​: rakudo-moar 97e47a​: OUTPUT«Any␤»

...except for native attributes​:

(01​:15​:36 PM) skids​: m​: class A { has int $.a = { 42.say; 43 }(); submethod BUILD () { } }.new().a.perl.say;
(01​:15​:36 PM) camelia​: rakudo-moar 97e47a​: OUTPUT«42␤43␤»
(01​:17​:06 PM) skids​: m​: class A { has int $.a = { 42.say; 43 }(); submethod BUILD () { $!a; } }.new().a.perl.say;
(01​:17​:07 PM) camelia​: rakudo-moar 97e47a​: OUTPUT«42␤43␤»

...which may or may not be related to the following, which results from some
cheating WRT figuring out whether a native attribute was touched​:

(01​:19​:22 PM) skids​: m​: class A { has int $.a = { 42.say; 43 }(); }.new(​:a(1)).a.perl.say;
(01​:19​:22 PM) camelia​: rakudo-moar 97e47a​: OUTPUT«1␤»
(01​:19​:27 PM) skids​: m​: class A { has int $.a = { 42.say; 43 }(); }.new(​:a(0)).a.perl.say;
(01​:19​:28 PM) camelia​: rakudo-moar 97e47a​: OUTPUT«42␤43␤»

...which makes it a bit difficult to set a native attribute to its "undefined" value if
it has a default.

@p6rt
Copy link
Author

p6rt commented Jan 27, 2016

From @skids

Just to add, a partial fix is in PR#​539 though there is a good chance it
is bitrotted by now.

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

No branches or pull requests

1 participant