Skip to content

Improve compiler error message COMPILER-70: The expression cannot be assigned to. #295

@mrcompator

Description

@mrcompator

Is your feature request related to a problem? Please describe.
I want to call a method from within the constructor. For this the method must be declared as static. Within the method I want to set a variable and so the variable must also be declared static. See example code below.

service SomeExampleService {

    static Boolean running = False;

    construct() {
        runSomething();
    }

    static void runSomething() {

        // just to be on the safe side in case it would run super long
        if (!running) {
            running = True;
            // do lots of stuff here
            running = False;
        }
    }
}

The compiler complains with:
COMPILER-70: The expression cannot be assigned to. ("running")

After talking to Gene and Cam they explained that static in this context also means final.

Describe the solution you'd like
Display a better error message why a value can't be assigned to a static variable. Any new devs coming from Java will very likely encounter the same problem and scratch their heads.
"The expression cannot be assigned to. ("running"). static makes the property final. Use a singleton service instead."

Describe alternatives you've considered
n/a

Additional context
n/a

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions