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

Capture with flattened array does not match #2989

Closed
p6rt opened this issue Dec 5, 2012 · 8 comments
Closed

Capture with flattened array does not match #2989

p6rt opened this issue Dec 5, 2012 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Dec 5, 2012

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

Searchable as RT116002$

@p6rt
Copy link
Author

p6rt commented Dec 5, 2012

From @bbkr

For sample class on Rakudo 2012.11

class A { method foo (Int) {} };

signature matches without problem when it is declared directly in code

say \(A, 1) ~~ A.^find_method("foo").signature;
True

but when signature is created from array it will not match

my @​t = 1; say \(A, @​t) ~~ A.^find_method("foo").signature;
False

Both signatures looks the same

say \(A, 1).perl
Capture.new( list => (A, 1).list, hash => EnumMap.new())
say \(A, @​t).perl
Capture.new( list => (A, 1).list, hash => EnumMap.new())

@p6rt
Copy link
Author

p6rt commented Dec 6, 2012

From @moritz

On Wed Dec 05 15​:00​:24 2012, pawel.pabian@​implix.com wrote​:

For sample class on Rakudo 2012.11

class A { method foo (Int) {} };

signature matches without problem when it is declared directly in code

say \(A, 1) ~~ A.^find_method("foo").signature;
True

but when signature is created from array it will not match

s/signature/capture/

my @​t = 1; say \(A, @​t) ~~ A.^find_method("foo").signature;
False

Both signatures looks the same

s/signatures/captures/

say \(A, 1).perl
Capture.new( list => (A, 1).list, hash => EnumMap.new())
say \(A, @​t).perl
Capture.new( list => (A, 1).list, hash => EnumMap.new())

That's a bug in Capture.perl, which flattens out the array @​t.

But Rakudo is correct to reject binding \(A, @​t) to (A, Int), because
Array !~~ Int.

If you do want to flatten out the @​t, write it as \(A, |@​t).

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 6, 2012

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

@p6rt
Copy link
Author

p6rt commented Dec 6, 2012

From @bbkr

But Rakudo is correct to reject binding \(A, @​t) to (A, Int), because
Array !~~ Int.

If you do want to flatten out the @​t, write it as \(A, |@​t).

That was the first thing I've tried, but it produces syntax error​:

$ perl6 -e 'my @​t; \(|@​t)'
===SORRY!===
CHECK FAILED​:
Undefined routine '&prefix​:<|>' called (line 1)

@p6rt
Copy link
Author

p6rt commented Dec 6, 2012

From @bbkr

I've also tried

\(A, @​t.flat)

and it still won't match

@p6rt
Copy link
Author

p6rt commented Mar 31, 2015

From @usev6

There were two different problems here​:

1) It was not possible to flatten an array within \(...).

This has been fixed​:

$ perl6 -e 'my @​t = 1, 2; say \(|@​t)'
\(1, 2)

[BTW​: It was possible to do 'Capture(|@​t)' before, only with the unary backslash operator it didn't work.]

The smartmatch from the OP also works with |@​t (but it fails as expected without flattening the array).

$ perl6 -e 'class A { method foo (Int) {} }; my @​t = 1; say \(A, |@​t) ~~ A.^find_method("foo").signature;'
True

$ perl6 -e 'class A { method foo (Int) {} }; my @​t = 1; say \(A, @​t) ~~ A.^find_method("foo").signature;'
False

I added a test to S02-types/capture.t with commit Raku/roast@7c4672ced8

2) Capture.perl flattens elements.

This is still an issue, but there is a separate ticket​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=114100. I'll link to that ticket, but since the main issue 1) is solved, I'm going to close this ticket as 'resolved'.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Mar 31, 2015

From @usev6

There were two different problems here​:

1) It was not possible to flatten an array within \(...).

This has been fixed​:

$ perl6 -e 'my @​t = 1, 2; say \(|@​t)'
\(1, 2)

[BTW​: It was possible to do 'Capture(|@​t)' before, only with the unary backslash operator it didn't work.]

The smartmatch from the OP also works with |@​t (but it fails as expected without flattening the array).

$ perl6 -e 'class A { method foo (Int) {} }; my @​t = 1; say \(A, |@​t) ~~ A.^find_method("foo").signature;'
True

$ perl6 -e 'class A { method foo (Int) {} }; my @​t = 1; say \(A, @​t) ~~ A.^find_method("foo").signature;'
False

I added a test to S02-types/capture.t with commit Raku/roast@7c4672ced8

2) Capture.perl flattens elements.

This is still an issue, but there is a separate ticket​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=114100. I'll link to that ticket, but since the main issue 1) is solved, I'm going to close this ticket as 'resolved'.

@p6rt
Copy link
Author

p6rt commented Mar 31, 2015

@usev6 - 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