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

Referring to an attribute in BUILD prevents it from getting its default value #4765

Open
p6rt opened this issue Nov 18, 2015 · 1 comment
Open

Comments

@p6rt
Copy link

p6rt commented Nov 18, 2015

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

Searchable as RT126680$

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @hoelzro

Excerpt from #perl6​:

  22​:42 hoelzro if the default logic happens after BUILD, then $!server is Str because BUILD doesn't set it up via its signature
  22​:43 m​: class Person { has $.name = 'John'; has $.age = 21; submethod BUILD(​:$!name) { say $!age } }; say Person.new(​:name<Rob>)
  22​:43 camelia rakudo-moar d410e3​: OUTPUT«(Any)␤Person.new(name => "Rob", age => Any)␤»
  ...
  22​:43 hoelzro m​: class Person { has $.name = 'John'; has $.age = 21; submethod BUILD() { say $!age } }; say Person.new(​:name<Rob>)
  22​:43 camelia rakudo-moar d410e3​: OUTPUT«(Any)␤Person.new(name => "John", age => Any)␤»
  ...
  22​:43 Juerd Right, but that would mean that I can't use any of the defaulting logic if I want other stuff to happen at initialization, using those defaults...
  22​:43 hoelzro hmm...that's interesting
  22​:43 m​: class Person { has $.name = 'John'; has $.age = 21; submethod BUILD() { } }; say Person.new(​:name<Rob>)
  22​:43 camelia rakudo-moar d410e3​: OUTPUT«Person.new(name => "John", age => 21)␤»
  22​:43 Juerd I can only imagine that this is an extremely common use case.
  ...
  22​:44 hoelzro it looks like referring to any attributes in BUILD circumvents their defaulting logic, which seems...odd.
  ...
  22​:44 Juerd I could just add the defaults to BUILD's signature, but it's so nice to have them all in one place :(
  22​:44 hoelzro Juerd​: I think that's a rakudobug

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