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

sub MAIN cannot accept enum argument #5808

Open
p6rt opened this issue Nov 18, 2016 · 9 comments
Open

sub MAIN cannot accept enum argument #5808

p6rt opened this issue Nov 18, 2016 · 9 comments
Labels
Bug LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Nov 18, 2016

Migrated from rt.perl.org#130131 (status was 'open')

Searchable as RT130131$

@p6rt
Copy link
Author

p6rt commented Nov 18, 2016

From @titsuki

See the following results​:

$ perl6 script.p6 --country=America
Usage​:
  script.p6 --country=<Country> 

$ perl6 script.p6 --country=1
Usage​:
  script.p6 --country=<Country> 

script.p6​:


use v6;

enum Country<China America Brazil>;

sub MAIN(Country :$country!) {
    say $country;
}


$ perl6 --version
This is Rakudo version 2016.10-295-g85c7072 built on MoarVM version 2016.10-71-g9d5c874
implementing Perl 6.c.

I think that if sub MAIN cannot accept enum argument, it should display any error messages and die.

@p6rt
Copy link
Author

p6rt commented Nov 18, 2016

From @lizmat

The parameters received from the command line, are always Str (or IntStr if they look like an integer). To allow direct matching / handling of this, we would need something like an EnumStr type. I don’t think that’s going to happen soon.

I also tried some pre-processing on the @​*ARGS array in an INIT block, but that fails because the default command line processing really expects something that works like a Str.

So, so far I’ve only been able to come up with this workaround​:

sub MAIN(​:$country! where (Country.enums{$_}​:exists)) {

}

Unfortunately it will display the feedback on a wrong parameter like​:

Usage​:
  script.pl --country=<Any>

but I guess that’s the best we have for this in the short-term.

On 18 Nov 2016, at 15​:40, Itsuki Toyota (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Itsuki Toyota
# Please include the string​: [perl #​130131]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130131 >

See the following results​:

$ perl6 script.p6 --country=America
Usage​:
script.p6 --country=<Country>

$ perl6 script.p6 --country=1
Usage​:
script.p6 --country=<Country>

script.p6​:
----
use v6;

enum Country<China America Brazil>;

sub MAIN(Country :$country!) {
say $country;
}
----

$ perl6 --version
This is Rakudo version 2016.10-295-g85c7072 built on MoarVM version 2016.10-71-g9d5c874
implementing Perl 6.c.

I think that if sub MAIN cannot accept enum argument, it should display any error messages and die.

@p6rt
Copy link
Author

p6rt commented Nov 18, 2016

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

@p6rt
Copy link
Author

p6rt commented Nov 18, 2016

From @lizmat

After some more investigation it turned out to be not so difficult in the MAIN parameter
handling case. So, fixed with 546dbd99b18425a42c8 . Tests needed!

On 18 Nov 2016, at 15​:40, Itsuki Toyota (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Itsuki Toyota
# Please include the string​: [perl #​130131]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130131 >

See the following results​:

$ perl6 script.p6 --country=America
Usage​:
script.p6 --country=<Country>

$ perl6 script.p6 --country=1
Usage​:
script.p6 --country=<Country>

script.p6​:
----
use v6;

enum Country<China America Brazil>;

sub MAIN(Country :$country!) {
say $country;
}
----

$ perl6 --version
This is Rakudo version 2016.10-295-g85c7072 built on MoarVM version 2016.10-71-g9d5c874
implementing Perl 6.c.

I think that if sub MAIN cannot accept enum argument, it should display any error messages and die.

@p6rt
Copy link
Author

p6rt commented Nov 18, 2016

From @zoffixznet

Tests added in Raku/roast@8ff3ab7391

@p6rt
Copy link
Author

p6rt commented Nov 18, 2016

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

@p6rt
Copy link
Author

p6rt commented Nov 19, 2016

From @zoffixznet

I'm re-opening this, as the Enum conversion is too eager now​: https://irclog.perlgeek.de/perl6-dev/2016-11-19#i_13595331

Basically, now MAIN can never take strings False or True, because those get converted to Bools and any other enums will fail to match, unless they're expected.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 19, 2016

From @zoffixznet

I'm re-opening this, as the Enum conversion is too eager now​: https://irclog.perlgeek.de/perl6-dev/2016-11-19#i_13595331

Basically, now MAIN can never take strings False or True, because those get converted to Bools and any other enums will fail to match, unless they're expected.

@p6rt
Copy link
Author

p6rt commented Nov 19, 2016

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

@p6rt p6rt added Bug LTA Less Than Awesome; typically an error message that could be better labels Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant