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

No runtime error when concatenating heterogeneous collections #128

Closed
echebbi opened this issue May 5, 2020 · 0 comments · Fixed by #137
Closed

No runtime error when concatenating heterogeneous collections #128

echebbi opened this issue May 5, 2020 · 0 comments · Fixed by #137

Comments

@echebbi
Copy link
Collaborator

echebbi commented May 5, 2020

Expected behavior

The interpreter stops its execution and prints an error when an attempt to concatenate two collections with incompatible types:

Sequence(String) self.numbers := Sequence{'on', 'two', 'three'};
self.numbers += Sequence{1, 2, 3};

Current behavior

The collections are actually concatenated. It seems to happen only when the left operand of += is a dynamic attribute (declared in ALE) or a local variable.

Origin of the issue

Due to Java's type erasure it is a bit hard to deal with heterogeneous collections at runtime. I guess they can be concatenated here because EMF allocates an EObject[] array when the variable is dynamic, and a more specific array when the feature is declared in Ecore.

How to fix

This is not straightforward to fix because the interpreter (MethodEvaluator):

  1. has no access to the declared type of a variable
    • could be solved by keeping all declarations (see variablesStack and caseVariableDeclaration)
  2. cannot evaluate the type of a value
    • might be solved by using an InsertionStrategy but it may likely require to validate the program first (as done by the type checker).

Anyway, the interpreter shouldn't know less about the program than the type checker. We have to address this.

How to test

There are already two tests in EvalTest, ready but ignored: this one and that one.

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

Successfully merging a pull request may close this issue.

1 participant