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

Type 'EnumerationLiteral' of model 'Model' cannot be instantiated #12

Closed
alfa-ryano opened this issue Feb 29, 2024 · 1 comment
Closed

Comments

@alfa-ryano
Copy link

alfa-ryano commented Feb 29, 2024

var enum = new Enumeration;
enum.name = "MyEnum";
var literal = new EnumerationLiteral;
literal.name = "FIRST";
enum.ownedLiteral.add(literal);

The EOL code above will throw this error (line 3):
Type 'EnumerationLiteral' of model 'Model' cannot be instantiated

This error appears on Cameo 2024x and MagicDraw 2021x (it only has been tested on these versions)

@agarciadom
Copy link
Member

This error had to do with the fact that when we create a new instance, we try to add it to the model. This isn't correct for EnumerationLiteral instances, as they can only live inside an Enumeration.

We now do a canAdd(...) check before we try to do this addition, but even that is not enough for EnumerationLiterals. In MagicDraw 2021x, canAdd(...) will happily report true for adding an EnumerationLiteral into the Model, despite this not being true. In this case, we just catch the IllegalArgumentException, log it with a warning, and return the newly created instance anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants