Should Raku typed enums work with custom types? I get compile errors when trying the following:
role A { }
class B does A { }
class C does A { }
my A enum E ( b => B, c => C );
results in
Cannot find method 'mro' on object of type Perl6::Metamodel::ParametricRoleGroupHOW
and
class D { }
my D enum F ( b => D.new, c => D.new );
results in
Cannot auto-generate a proto method for 'Int' in the setting
or does this fall under
Complex expressions for generating key-value pairs are not supported.
EDIT
Regarding the first example - it looks like Raku doesn't like roles as the type constraint. The same error is given when trying, e.g.
my Rational enum G ( one => 1/1, two => 1/2 );
and as for what I was really hoping for:
Using a type object as a value for an enum not yet implemented. Sorry.
The problem is most like that only
IntandStrare actually tested thoroughly.For example, your
Rationalone wouldn't even work correctly if you had usedRatinstead.That should say
1to be consistent withIntenums and.Int, and toStrenums and.StrSo the reason for this error:
Is that Rakudo assumes that anything other than a
Strenum must be anIntenum.What it should do is generate a method that is the same name as the class that returns a value that isn't boxed by the enum.
If it doesn't even work correctly for
Rat, which compiles and is a built-in type; then a user defined one doesn't stand a chance. That applies doubly to a role.TL;DR
It is a bug. (actually at least two)