Anonymous Apex doesn't support properties at the top-level
Issue #2079
new
This one is weird, using latest 2.2.1.5
Two identical statements, first one shows inspection error; second doesn’t. Compiles fine. Appears to be limited to first use of get
String x {get { return 'a'} private set;}
String y {get {return 'b'} private set;}
Comments (3)
-
repo owner -
repo owner - edited description
- removed version
-
repo owner - changed title to Anonymous Apex doesn't support properties at the top-level
- Log in to comment
The issue here is that the parser is seeing those a local variable declaration statements and not property declarations. Without going into more detail than anyone other than me likely needs, I'm currently jumping through some hoops to facilitate flexibility in what is allowed in Apex source including actual Apex source files, anonymous Apex script files, standalone SOQL queries, etc., while also providing the level of quick parser recovery required by an IDE so that one syntax error doesn't result in a huge number of perceived downstream errors. This is the side-effect of such an approach.
Of course, this is valid Apex--well, it's technically not because you haven't terminated the
return
statements in the read accessors, but with those corrections in place--IC2's Apex parser should be able to parse it successfully. However, given that it's such a corner case, and given that pulling one thread here will almost certainly pull other threads as well making this likely non-trivial to address, this would be one of those rare times I'd recommend a simple workaround. If you add apublic
visibility specifier to each of these declarations, IC2 parses them properly, i.e.:It's certainly not an ideal response to a legitimate bug, and I'm not going to resolve this since it's not fixed, but it's also unlikely to rise to the top of the queue anytime soon given the risk/reward of a fix weighed against the likelihood of folks encountering the issue combined with the reasonable existing workaround.