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

Class attribute constraints applied on elements of array attribute, not the attribute itself #1414

Open
jkramer opened this issue Jan 16, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@jkramer
Copy link
Contributor

commented Jan 16, 2018

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 foo(@three-things where *.elems == 3) {
  say "Got three things! {@three-things.gist}";
}(<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.
@lizmat

This comment has been minimized.

Copy link
Contributor

commented Jan 16, 2018

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented Jan 16, 2018

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?

@lizmat

This comment has been minimized.

Copy link
Contributor

commented Jan 16, 2018

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented Jan 16, 2018

https://irclog.perlgeek.de/perl6/2018-01-16#i_15697385

<TimToady> someone probably just implemented the one as an anonymous subset,
       so it distributes like a subset type
<TimToady> we should probably make them consistent 

(there's more discussion in the chat)

P.S.: &-sigils are similarly affected

P.P.S.: there appear to be some glitches with Subset @foo parameter constraints; see here and here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.