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

is default value not applied to attributes by default #6285

Closed
p6rt opened this issue May 28, 2017 · 9 comments
Closed

is default value not applied to attributes by default #6285

p6rt opened this issue May 28, 2017 · 9 comments

Comments

@p6rt
Copy link

p6rt commented May 28, 2017

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

Searchable as RT131387$

@p6rt
Copy link
Author

p6rt commented May 12, 2017

From @lizmat

<lizmat> m​: class A { has Int $.a is default(42) }; dd A.new.a # expected to see 42 there, not Int, so feels like "is default" on attrs isn't implemented?
<+camelia> rakudo-moar a9a161​: OUTPUT​: «Int␤»
<lizmat> m​: my Int $a is default(42); say $a
<+camelia> rakudo-moar a9a161​: OUTPUT​: «42␤»
<lizmat> m​: class A { has Int $.a is default(42) }; use nqp; dd nqp​::getattr(A.CREATE,A,q/$!a/).VAR.default # oddly enough, it appears to be set
<+camelia> rakudo-moar a9a161​: OUTPUT​: «42␤»
<lizmat> class A { has Int $!a is default(42); method a() is raw { $!a } }; dd A.CREATE.a # but this doesn't :-(
<+camelia> rakudo-moar a9a161​: OUTPUT​: «Int $!a = Int␤»

This doesn’t seem to be cause by BUILD, as the .CREATE part bypasses all of that.

Weird!

@p6rt
Copy link
Author

p6rt commented May 13, 2017

From @b2gills

On Fri, 12 May 2017 03​:04​:46 -0700, elizabeth wrote​:

<lizmat> m​: class A { has Int $.a is default(42) }; dd A.new.a
# expected to see 42 there, not Int, so feels like "is default" on
attrs isn't implemented?

It does work if you add =Nil

  class A { has Int $.a is rw is default(42) = Nil };
  dd A.new.a; # 42
  $_ = A.new(​:a(34));
  .a = Nil;
  dd .a; # 42

@p6rt
Copy link
Author

p6rt commented May 13, 2017

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

@p6rt
Copy link
Author

p6rt commented May 13, 2017

From @lizmat

On 13 May 2017, at 03​:45, Brad Gilbert via RT <perl6-bugs-followup@​perl.org> wrote​:
On Fri, 12 May 2017 03​:04​:46 -0700, elizabeth wrote​:

<lizmat> m​: class A { has Int $.a is default(42) }; dd A.new.a
# expected to see 42 there, not Int, so feels like "is default" on
attrs isn't implemented?

It does work if you add =Nil

class A { has Int $.a is rw is default(42) = Nil };
dd A.new.a; # 42
$_ = A.new(​:a(34));
.a = Nil;
dd .a; # 42

The whole reason for me to look at this, was to prevent the explicit initialization, done by BUILDALL. If you don’t, it still doesn’t work​:

$ 6 'class A { has Int $.a is rw is default(42) = Nil }; say A.CREATE.a'
(Int)

:-(

@p6rt
Copy link
Author

p6rt commented May 28, 2017

From @zoffixznet

$z is `Nil` without my having to assign anything, while `$!z` is Any. To make `$!z` Nil I also have to assign Nil to it​:

<Zoffix___> m​: my $z is default(Nil); dd $z; class Foo { has $!z is default(Nil); method x { dd $!z } }.new.x
<camelia> rakudo-moar 0c5fe5​: OUTPUT​: «Nil $z = Nil␤Any $!z = Any␤»

@p6rt
Copy link
Author

p6rt commented Sep 12, 2017

From @jnthn

On Sat, 27 May 2017 19​:35​:53 -0700, cpan@​zoffix.com wrote​:

$z is `Nil` without my having to assign anything, while `$!z` is Any.
To make `$!z` Nil I also have to assign Nil to it​:

<Zoffix___> m​: my $z is default(Nil); dd $z; class Foo { has $!z is
default(Nil); method x { dd $!z } }.new.x
<camelia> rakudo-moar 0c5fe5​: OUTPUT​: «Nil $z = Nil␤Any $!z = Any␤»

Seems fixed, test needed.

13​:56 < jnthn> m​: class Foo { has $!z is default(Nil); method x { dd $!z } }.new.x
13​:56 <+camelia> rakudo-moar 760530​: OUTPUT​: «Nil $!z = Nil␤»

@p6rt
Copy link
Author

p6rt commented Sep 12, 2017

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

@p6rt
Copy link
Author

p6rt commented Sep 14, 2017

From @skids

On Tue, 12 Sep 2017 06​:57​:13 -0700, jnthn@​jnthn.net wrote​:

On Sat, 27 May 2017 19​:35​:53 -0700, cpan@​zoffix.com wrote​:

$z is `Nil` without my having to assign anything, while `$!z` is Any.
To make `$!z` Nil I also have to assign Nil to it​:

<Zoffix___> m​: my $z is default(Nil); dd $z; class Foo { has $!z
is
default(Nil); method x { dd $!z } }.new.x
<camelia> rakudo-moar 0c5fe5​: OUTPUT​: «Nil $z = Nil␤Any $!z = Any␤»

Seems fixed, test needed.

13​:56 < jnthn> m​: class Foo { has $!z is default(Nil); method x { dd
$!z } }.new.x
13​:56 <+camelia> rakudo-moar 760530​: OUTPUT​: «Nil $!z = Nil␤»

Tests done in roast 563f957d06, so resolving.

@p6rt
Copy link
Author

p6rt commented Sep 14, 2017

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

@p6rt p6rt closed this as completed Sep 14, 2017
@p6rt p6rt added the testneeded label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant