Repository navigation
apex func_start false-positives on new ClassName( constructor calls #1963
Description
Summary
GitGalaxy's apex func_start regex (gitgalaxy/standards/language_standards.py, apex rule
block) misidentifies new ClassName(...) object-instantiation expressions as function/method
definitions when the new keyword sits at the start of a source line -- a common shape in
multi-line SObject-builder calls, e.g.:
Account acct = (Account) TestFactory.createSObject(
new Account(name = 'Original Name'),
true
);Line 2 above (new Account(name = 'Original Name'),) gets matched as a function definition named
Account.
Root cause
The regex's optional return-type/modifier prefix group --
(?:[a-zA-Z_][\w.]*(?:generics)?(?:\[\])*\s+)? -- accepts any identifier-shaped token followed
by whitespace at the start of a line, with no exclusion list beyond the captured name itself
(class|interface|enum|if|for|while|switch|catch). new is a reserved instantiation keyword in
Apex, never a legitimate return type or modifier, but nothing excludes it from that prefix slot.
So new Account( parses as "return type = new, function name = Account" and passes the #1221
gating fix (which only requires the line start with some annotation/modifier/return-type-shaped
token, not that the token be a real one).
tree-sitter does not make this mistake: its Apex grammar structurally distinguishes
object_creation_expression from method_declaration.
Evidence
Discovered via the tri-comparison ledger
(apex/function/existence/agree[gitgalaxy]_vs[tree_sitter], 2 sampled occurrences,
AuraEnabledRecipes_Tests.cls:25 and :43). Confirmed by direct source read and by running the
regex standalone against the whole language-crucible/data/apex corpus, which surfaces the same
shape 6 times across 2 files:
apex-recipes/AuraEnabledRecipes_Tests.cls:6,25,43--new Account(...)apex-recipes/SOQLRecipes_Tests.cls:226,235--new Account(...)apex-recipes/SOQLRecipes_Tests.cls:504--new Opportunity(...)
All 6 are multi-line constructor-call arguments, none are real method/constructor definitions.
Suggested fix
Exclude new from the optional return-type/modifier prefix group in the apex func_start (and
likely args, which shares the identical prefix shape) regex -- e.g. a negative lookahead
(?!new\b) immediately before that group, so new can never be consumed as a pseudo return type.
Ledger
Tracked as validated in docs/self_scan/tri_comparison_ledger.json under
apex/function/existence/agree[gitgalaxy]_vs[tree_sitter] -- see that entry's verdict for the
full investigation writeup.
Activity
squid-protocol commentedon Aug 20, 2026
Incidental-finding follow-up: checked whether this same shape exists in sibling C-family/OOP
languages'
func_startregexes (csharp, java, groovy, dart, kotlin, scala, php) by running eachone standalone against its own language-crucible corpus. None reproduce it -- and the reason is
that csharp (and java/groovy/dart, which share its lineage) already carries an explicit exclusion
for this exact shape:
right before the optional return-type/modifier prefix group. Apex is simply the one language in
this family that never got this fix applied. The suggested fix above (
(?!new\b)immediatelybefore apex's own equivalent prefix group) is this same established, already-proven-safe pattern
-- not a new design.
tri-comparison: validate apex func_start existence shape, file #1963 (#…
docs(language-status): add apex.md (#1966)
fix(detector,apex): exclude `new` from func_start/args return-type pr…