BrowserREPL-button-tip-on BrowserREPL-button-tip-off

EditButtonTip 2021-04-05

class X::Does::TypeObject

Error due to mixing into a type object

class X::Does::TypeObject is Exception {}
Code

When you try to add one or more roles to a type object with does after it has been composed, an error of type X::Does::TypeObject is thrown:

Mu does Numeric;    # Cannot use 'does' operator with a type object.
Code

The correct way to apply roles to a type is at declaration time:

class GrassmannNumber does Numeric { ... };
role AlgebraDebugger does IO { ... };
grammar IntegralParser does AlgebraParser { ... };
Code

Roles may only be runtime-mixed into defined object instances:

GrassmannNumber.new does AlgebraDebugger;
Code

(This restriction may be worked around by using augment or supersede, or with dark Metamodel magics, but this will likely result in a significant performance penalty.)

Methods§

method type§

method type(X::Does::TypeObject:D: --> Mu:U)
Code

Returns the type object into which the code tried to mix in a role.