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

an enum does not smartmatch in given ... { when ... { ... } } #812

Closed
p6rt opened this issue Mar 21, 2009 · 4 comments
Closed

an enum does not smartmatch in given ... { when ... { ... } } #812

p6rt opened this issue Mar 21, 2009 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 21, 2009

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

Searchable as RT64046$

@p6rt
Copy link
Author

p6rt commented Mar 21, 2009

From autoexec@xs4all.nl

Unsure whether the following should work, but it doesn't​:

perl6 -e 'enum E <foo bar>; my E $x=E​::bar; given $x { when E​::foo {say
"FOO"} when E​::bar {say "BAR"}};'
Method 'ACCEPTS' not found for invocant of class ''

The problem seems to be that the 'when' cannot perform a smart match on an
enum member. A workaround is to cast the enum member to an int, but this
is surely not as intended​:

perl6 -e 'enum E <foo bar>; my E $x=E​::bar; given $x { when int E​::foo
{say "FOO"} when int E​::bar {say "BAR"}};'
BAR

The workaround is successful for example around line 442 etc of
http://github.com/eric256/perl6-examples/blob/master/lib/Pod/Parser.pm

See also​: http://rt.perl.org/rt3/Public/Bug/Display.html?id=63878

@p6rt
Copy link
Author

p6rt commented May 1, 2009

From @jnthn

On Sat Mar 21 02​:42​:29 2009, autoexec@​xs4all.nl wrote​:

Unsure whether the following should work, but it doesn't​:

perl6 -e 'enum E <foo bar>; my E $x=E​::bar; given $x { when E​::foo {say
"FOO"} when E​::bar {say "BAR"}};'
Method 'ACCEPTS' not found for invocant of class ''

The problem seems to be that the 'when' cannot perform a smart match on an
enum member.

That was the problem, and it's now fixed in e33c004; unfudged some tests
for smartmatching on enum values, added a couple to S12-enums/basic.t
that explicitly try it out with given/when.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented May 1, 2009

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

@p6rt
Copy link
Author

p6rt commented May 1, 2009

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

@p6rt p6rt closed this as completed May 1, 2009
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant