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

Mixing parameterized role into enum value causes compile-time error #5515

Open
landyacht opened this issue Jan 20, 2024 · 5 comments
Open

Mixing parameterized role into enum value causes compile-time error #5515

landyacht opened this issue Jan 20, 2024 · 5 comments
Labels
LTA Less Than Awesome; typically an error message that could be better objects OOP, classes, instances, roles, inheritance, (sub)methods, etc.

Comments

@landyacht
Copy link

The Problem

With more than one value in an enum, mixing a parameterized role into the value yields the obtuse comile-time error "Incompatible MROs in P6opaque rebless for types Int+{MixedInRoleName[Str]} mixin and EnumName". This does not happen when there is only one enum value, nor when the role is unparameterized.

Steps to Reproduce

role MixedInRoleName[$a] { has $.a = $a; }
enum EnumName (
    KeyOne => 1 but MixedInRoleName['Yksi'],
    KeyTwo => 2 but MixedInRoleName['Kaksi']
);

Environment

  • Operating system: Linux 6.1.53-gentoo-r1 (reproduced also with raku eval bot in IRC)
  • Raku version: Rakudo 2023.12 / MoarVM 2023.12
@lizmat
Copy link
Contributor

lizmat commented Jan 21, 2024

ping @vrurg

@vrurg
Copy link
Member

vrurg commented Jan 21, 2024

It lurks in my memory that values of an enum has to be of the same type. No way for me to recall where I saw this, neither I can find the place at the moment.

Trying to mix a number and a string results in exactly the same error. Apparently, the error itself is LTA, but otherwise it seems to be legal.

The particular example case can be easily fixed with this:

role MixedInRoleName { has $.a; }
enum EnumName (
    KeyOne => (1 but MixedInRoleName('Yksi')),
    KeyTwo => (2 but MixedInRoleName('Kaksi'))
);
say KeyOne.a;

Minor offtop: I still remember myself thinking "what the hell this 'mixin attribute' means and why would I need it?" :)

@landyacht
Copy link
Author

Interesting. I suppose technically roles that are parameterized differently do cause the resulting type to be different. Still, might be worth leaving this open to improve the error message?

@ab5tract ab5tract added LTA Less Than Awesome; typically an error message that could be better objects OOP, classes, instances, roles, inheritance, (sub)methods, etc. labels Jan 22, 2024
@vrurg
Copy link
Member

vrurg commented Jan 22, 2024

Still, might be worth leaving this open to improve the error message?

Absolutely.

@vrurg
Copy link
Member

vrurg commented Jan 22, 2024

I suppose technically roles that are parameterized differently do cause the resulting type to be different.

Yes, you're correct. This is why the approach you took in your example is not the best one in some scenarios. Imagine one having thousands of objects to be marked with roles-labels. In this case they get thousands of additional types, each consuming memory both to hold its VM representation and to maintain metaobject data related to the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better objects OOP, classes, instances, roles, inheritance, (sub)methods, etc.
Projects
None yet
Development

No branches or pull requests

4 participants