Skip Menu |
Report information
Id: 128076
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cookbook_000 [at] yahoo.co.jp <titsuki [at] cpan.org>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Couldn't assign an native int value to an enum object
Download (untitled) / with headers
text/plain 333b
See the following results. perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; my day $day = 0;' Type check failed in assignment to $day; expected day but got Int (0) in block <unit> at -e line 1 The above behavior is different from the explanation of the spec page's one. https://design.perl6.org/S12.html#Value_Generation
Download (untitled) / with headers
text/plain 562b
P.S. My Perl 6 version is $ perl6 --version This is Rakudo version 2016.04-99-g475063a built on MoarVM version 2016.04 implementing Perl 6.c. On 2016-5月-05 木 18:08:19, cookbook_000@yahoo.co.jp wrote: Show quoted text
> See the following results. > > perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; my day $day = 0;' > Type check failed in assignment to $day; expected day but got Int (0) > in block <unit> at -e line 1 > > > The above behavior is different from the explanation of the spec page's one. > https://design.perl6.org/S12.html#Value_Generation
Download (untitled) / with headers
text/plain 1.6k
This doesn't look like a bug to me; just a case where ideas from the synopses did not make it into the language. The synopses are not the "spec", they are just design documents. I also don't see how your assignment could work, considering how enums ended up behaving in Perl 6.c. As you can see from the output of the .^mro introspection method, your enum type inherits from Int, and not the other way around: ➜ perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; say day.^mro' ((day) (Int) (Cool) (Any) (Mu)) A variable with a type constraint for a specific type, cannot be assigned a value of its *parent* type. Furthermore, it looks to me like the example that you cite from S12, is meant to be about *native* types - i.e. "int" rather than "Int". According to the ideas expressed there, an enum with a lowercase name would automatically be of that native "int" type, as if you had explicitly written: ➜ perl6 -e 'my int enum day <Sun Mon Tue Wed Thu Fri Sat>;' And then some magic could potentially happen with assignments. Alas, native-typed enums apparently did not make it into Perl 6.c at all (the previous example fails with an internal error), and there are no tests related to them in the official test suite (which is the true "spec"): https://github.com/perl6/roast/tree/master/S12-enums In any case, I have a feeling that some of the synopses were written at a time when native types were thought to be something slightly different than what they actually ended up being. For these reasons, I changed the title of this issue to reflect that it is not a bug, but rather an idea that could potentially be investigated for future Perl 6.c versions.
Download (untitled) / with headers
text/plain 1.9k
Thank you for your reply ! Show quoted text
> The synopses are not the "spec", they are just design documents.
I'll be careful to this point from now on. On 2016-5月-06 金 05:36:34, smls75@gmail.com wrote: Show quoted text
> This doesn't look like a bug to me; just a case where ideas from the > synopses did not make it into the language. The synopses are not the > "spec", they are just design documents. > > I also don't see how your assignment could work, considering how enums > ended up behaving in Perl 6.c. As you can see from the output of the > .^mro introspection method, your enum type inherits from Int, and not > the other way around: > > ➜ perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; say > day.^mro' > ((day) (Int) (Cool) (Any) (Mu)) > > A variable with a type constraint for a specific type, cannot be > assigned a value of its *parent* type. > > Furthermore, it looks to me like the example that you cite from S12, > is meant to be about *native* types - i.e. "int" rather than "Int". > According to the ideas expressed there, an enum with a lowercase name > would automatically be of that native "int" type, as if you had > explicitly written: > > ➜ perl6 -e 'my int enum day <Sun Mon Tue Wed Thu Fri Sat>;' > > And then some magic could potentially happen with assignments. > > Alas, native-typed enums apparently did not make it into Perl 6.c at > all (the previous example fails with an internal error), and there are > no tests related to them in the official test suite (which is the true > "spec"): > https://github.com/perl6/roast/tree/master/S12-enums > In any case, I have a feeling that some of the synopses were written > at a time when native types were thought to be something slightly > different than what they actually ended up being. > > For these reasons, I changed the title of this issue to reflect that > it is not a bug, but rather an idea that could potentially be > investigated for future Perl 6.c versions.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org