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

positional attributes initialized via .new are assigned as a list (with flattening) instead of bound #3670

Closed
p6rt opened this issue Feb 8, 2015 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Feb 8, 2015

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

Searchable as RT123757$

@p6rt
Copy link
Author

p6rt commented Feb 8, 2015

From @raydiak

Relevant snippets starting at http://irclog.perlgeek.de/perl6/2015-02-08#i_10078888 :
Irrelevant distractions filtered out where indicated by ...

05​:59​:49 raydiak | m​: class Foo { has @​.bar }; Foo.new​: :bar(1,2,3); Foo.new(bar => (1,2,3)); Foo.new​: bar => [1,2,3]; # <-- fil__
05​:59​:50 +camelia | rakudo-moar d26211​: ( no output )
06​:00​:31 fil__ | ok
06​:00​:37 fil__ | guess they all work!
06​:00​:51 fil__ | what's preferred? () or []?
06​:01​:42 raydiak | () makes a parcel which gets flattened into @​.bar ... [] makes an array which does the same...preference really
...
06​:03​:52 raydiak | hm
06​:04​:34 raydiak | m​: class Foo { has @​.bar }; say Foo.new(​:bar(1,2,3)).bar.WHAT; say Foo.new(bar => [1,2,3]).bar.WHAT;
06​:04​:36 +camelia | rakudo-moar d26211​: OUTPUT«(Array)␤(Array)␤»
06​:05​:10 raydiak | m​: class Foo { has @​.bar }; say Foo.new( bar => (1,2,3) ).bar.WHAT;
06​:05​:11 +camelia | rakudo-moar d26211​: OUTPUT«(Array)␤»
06​:05​:17 raydiak | m​: class Foo { has @​.bar }; say Foo.new( bar => Parcel.new(1,2,3) ).bar.WHAT;
06​:05​:18 +camelia | rakudo-moar d26211​: OUTPUT«(Array)␤»
06​:05​:25 raydiak | yep, no difference in the end
...
06​:09​:06 raydiak | m​: class Foo { has @​.bar }; say Foo.new( bar => Blob[uint8].new(1,2,3) ).bar.WHAT;
06​:09​:07 +camelia | rakudo-moar d26211​: OUTPUT«(Array)␤»
06​:10​:58 raydiak | so the type of the positional thing you pass into an @​ attribute at initialization doesn't matter? iow always list assignment, not binding?
06​:11​:09 TimToady | hmm
06​:11​:42 TimToady | m​: class Foo { has @​.bar }; say Foo.new( bar => [1,2,3] ).bar.elems
06​:11​:43 +camelia | rakudo-moar d26211​: OUTPUT«3␤»
06​:12​:20 TimToady | but apparently loses the itemization somewhere
06​:12​:47 TimToady | you'd only get 1 elem if you assigned [1,2,3] directly to @​foo
06​:12​:51 raydiak | I thought I should be wrong about that after I explained it, but...it seems to always gives a flattened Array, regardless of what you pass in or whether it's itemized or not
06​:13​:06 TimToady | yeah, something a little odd going on there
06​:13​:26 TimToady | probably calling .list on the initializer
06​:14​:17 * | raydiak will rakudobug after impending dinner

@p6rt
Copy link
Author

p6rt commented Nov 28, 2015

From @jnthn

On Sun Feb 08 01​:22​:03 2015, raydiak@​cyberuniverses.com wrote​:

...
06​:11​:09 TimToady | hmm
06​:11​:42 TimToady | m​: class Foo { has @​.bar }; say Foo.new( bar =>
[1,2,3] ).bar.elems
06​:11​:43 +camelia | rakudo-moar d26211​: OUTPUT«3␤»
06​:12​:20 TimToady | but apparently loses the itemization somewhere
06​:12​:47 TimToady | you'd only get 1 elem if you assigned [1,2,3]
directly to @​foo

These days, that 3 is correct, because after the GLR [1,2,3] is no longer an item and assignment follows the 1-arg rule. There was still a bug, however; this gave 3​:

class Foo { has @​.bar }; say Foo.new( bar => $[1,2,3] ).bar.elems

When it should have given 1. I've fixed that, and added tests in S12-attributes/instance.t.

@p6rt
Copy link
Author

p6rt commented Nov 28, 2015

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

@p6rt
Copy link
Author

p6rt commented Nov 28, 2015

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

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