On the anonymous apex valid code highlighted as error

Issue #1738 resolved
Aliaksandr Luferau created an issue

code:

class Test {
    Test(String field) {
        this.field = field;
    }
    public String field;
}

Test cnt1 = new Test('test');  // <-- this line have error: 'Test' unexpected
Test cnt2;

but this code successfully executed

Comments (3)

  1. Piotr Kożuchowski

    I just wanted to report this myself 🙂 Anonymous apex behaves like body of a class, but editor goes crazy as soon as you declare a class in script.

    It has been bothering me for years.

  2. Log in to comment