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
Class attribute constraints applied on elements of array attribute, not the attribute itself #1414
Comments
|
I don’t think this is a bug, although maybe a bug in documentation.
The where clause is applied to the descriptor of the array, which governs the elements of the array.
If you only want 3 element lists, you should probably used shaped arrays:
class A {
has @.a[3]
}
dd A.new(a => [1,2,3,4]); # Index 3 for dimension 1 out of range (must be 0..2)
dd A.new(a => [1,2,3]); # A.new(a => Array.new(:shape(3,), [1, 2, 3]))
HTH
… On 16 Jan 2018, at 17:12, Jonas Kramer ***@***.***> wrote:
The Problem
When adding a where constraint on a class attribute of type Array (others might be affected as well though), the constraint is applied to the elements of the array instead of the array attribute itself as one would expect.
Expected Behavior
The constraint checks should be performed on the attribute, not its array elements.
Actual Behavior
It seems like the constraint is applied to the elements of the array attribute.
Steps to Reproduce
# This crashes:
class Foo {
has @.three-things where *.elems == 3;
}.new(three-things => <three excellent things>);
# This works, as apparently the where is applied to each of the three strings
# instead of @.three-things itself:
class Bar {
has @.three-things where *.chars > 3;
}.new(three-things => <three excellent things>);
# This however works as expected:
sub ***@***.*** where *.elems == 3) {
say "Got three things! ***@***.***}";
}(<exactly three things>);
Environment
• Linux 4.11.2-1-ARCH #1 SMP PREEMPT Mon May 22 06:53:49 CEST 2017 x86_64 GNU/Linux
• This is Rakudo version 2017.07-105-gc8c5c7129 built on MoarVM version 2017.07-266-ged84a632 implementing Perl 6.c.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
How come it applies to the Array itself when it's part of the routine's parameters? |
|
A very good question. I think TimToady / jnthn should have a say about this.
… On 16 Jan 2018, at 17:28, Zoffix Znet ***@***.***> wrote:
The where clause is applied to the descriptor of the array, which governs the elements of the array.
How come it applies to the Array itself when it's part of the routine's parameters?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
https://irclog.perlgeek.de/perl6/2018-01-16#i_15697385 (there's more discussion in the chat) P.S.: P.P.S.: there appear to be some glitches with |
|
I'm thinking this issue's title should be changed to "Problems with subset/where constraints applied to variables/parameters/attributes with anything other than $ sigil". Any objections? As background info, I found this bug to be the nearest match for a scenario I just encountered: yields In a comment above @zoffixznet has provided links to some IRC chat exchanges and added "P.S.: The IRC links in Zoffix's comment are broken; here's what I think they are supposed to be pointed to: |
The Problem
When adding a
whereconstraint on a class attribute of type Array (others might be affected as well though), the constraint is applied to the elements of the array instead of the array attribute itself as one would expect.Expected Behavior
The constraint checks should be performed on the attribute, not its array elements.
Actual Behavior
It seems like the constraint is applied to the elements of the array attribute.
Steps to Reproduce
Environment
The text was updated successfully, but these errors were encountered: