Apex Compiler Changes

It appears that recently the Apex compiler has changed – for the better it seems.

Here are some typical messages:

Example 1:

String s = "hey";

Results:

Error:Error:line (6)Unrecognized symbol '"', which is not a valid Apex identifier.
Error:Error:line (6)Unrecognized symbol '"', which is not a valid Apex identifier.
Error:Error:line (1)". Message was "no viable alternative at character '"'".
Error:Error:line (1)". Message was "no viable alternative at character '"'".
Error:Error:line (6)Variable does not exist: hey

Example 2:

Integer x = 0
String y = 'something';

Results:

Error:(7, 5) unexpected syntax: 'missing SEMICOLON at 'String''

Example 3:

if (true == true))

Results:

Error:(6, 22) unexpected token: ')'

Example 4:

String[] stuff = new String[]{'whats up'

Results:

Error:(9, 5) unexpected syntax: 'mismatched input 'VestingData' expecting RCURLY'

The messages appear more specific and clear – however, I can’t find any org which still has the old compiler to compare with.

Does anyone have any insight into this pleasant phenomenon?

Specifically:

  • Are there any important differences between the old compiler and the new?
  • Does the new compiler provide any new functionality that I could take
    advantage of?
  • How has the apparent speed increase been achieved?
  • Is there a concrete roadmap of future updates that we should know about?

Answer

I can confirm that the new Apex compiler appears to be in place.

I took the first example from Winter ’18 Apex Compiler Changes and tested in out in my dev org. It no longer compiles with Summer’17 Patch 19.2. It isn’t immediately clear if the Apex compiler is tied to the release version.

enter image description here

Winter 18 came early! At least as far as the compiler is concerned.

The help article linked above contains the “important differences between the old compiler and the new”.

I suspect you will see some new Apex functionality going forward once the compiler is settled in place. These would usually be heralded by the release notes. Things like Deployments Now Recompile of All Apex Code and the @isTest(isParallel=true) spring to mind as being related to the new compiler. This is just a guess on my part.

Attribution
Source : Link , Question Author : Caspar Harmer , Answer Author : Daniel Ballinger

Leave a Comment