gemoc / ale-lang

Action Language for EMF
Eclipse Public License 1.0
8 stars 6 forks source link

result can't be used in expressions when not initialized #191

Open echebbi opened 4 years ago

echebbi commented 4 years ago

Bug description

Using result in an expression leads to a runtime error during interpretation. For example, the following code produces an error during the evaluation of the if's condition:

class A {

    def boolean isX() {
        if (result) {

        }
        result := false;
    }

}

The error is "Couldn't find the 'result' variable".

Expected behavior

Not sure. One of the following:

How to reproduce

Steps to reproduce the behavior:

  1. Create an ALE project
  2. Write a semantics that uses result in an expression as shown above
  3. Run the interpreter

Additional context

Issue caused by the following line:

https://github.com/gemoc/ale-lang/blob/a1a0bf83da3c2228b127d4dc73e3bf733f1b9b9e/plugins/org.eclipse.emf.ecoretools.ale.core/src/org/eclipse/emf/ecoretools/ale/core/interpreter/internal/MethodEvaluator.java#L688

Since result has not been initialized yet, the map returned by scopes.getCurrent().getVariableValues() won't contain it. The appropriate fix depends on the chosen solution.