Page MenuHomePhabricator

XHPAST fails to recognise some syntax errors
Closed, ResolvedPublic

Description

XHPAST does not detect a syntax error with the following code (specifically, the ArcanistXHPASTLinter does not raise any issues):

<?php

class Foo {
  public final final function bar() {}
}

php -l does recognise this code as a syntax error:

>  php -l test.php
PHP Fatal error:  Multiple final modifiers are not allowed in test.php on line 5
Errors parsing test.php

Event Timeline

joshuaspence claimed this task.
joshuaspence raised the priority of this task from to Needs Triage.
joshuaspence updated the task description. (Show Details)
joshuaspence added a project: XHPAST.
joshuaspence added a subscriber: epriestley.
joshuaspence added a subscriber: joshuaspence.

I don't mind working on this, but I'm not sure what the correct fix is.

This is not a syntax error, per se, in PHP -- the error would say something like "PHP Parse error: syntax error, unexpected 'final'..." if it was. I think it gets raised a little later on in the compile phase. So that's the technical reason why we don't detect it.

We could probably raise this as a syntax error (or syntax-like error) instead and be better off overall, but I think the path to doing that isn't very straightforward. It's hard to encode "optionally, any of these words, in any order, but not more than once" in a grammar, which is why PHP raises the error later.

We can probably inspect the subtree after building it but before attaching it to the main tree and raise an issue there.

However, I think older PHP was OK with, e.g, public public public m(), at least. It's probably fine if we're more strict than older PHP about something like this (which is relatively indefensible), but maybe worth noting at least.

A related case with try..catch..finally (see D10337) works in the same way as @epriestley described. However, in that case it's easy to fix. This may be less trivial, but still worth fixing.

joshuaspence claimed this task.

This was sorta fixed by D12922.