Page MenuHomePhabricator

Allow ifs without else and reject empty conditions (because CachingParser doesn't support empty if)
Closed, ResolvedPublic

Description

Currently, it's not possible to do something like

if ( 1==1 ) then
( var := 'x' )
end;

as the parser will complain about a missing else. This could potentially be fine, since if you don't want an else you can use a no-op like

if ( 1==1 ) then
( var := 'x' )
else
()
end;

However, code like that can fail with the CachingParser if the if branch is empty. For instance,

if ( 1=== 1 ) then
() 
else ( false )
end;

Yes, that could be inverted to make the else branch empty, but people should not be forced to do so. Instead, I'd propose to:

  1. Accept ifs without an else
  2. Require that the if condition is not empty

As a temporary workaround, it could also be fine to make CachingParser support empty conditions, but anyway we have to fix the issue before deploying CachingParser in prod.

Event Timeline

Daimona created this task.Aug 19 2019, 3:22 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 19 2019, 3:23 PM
Daimona renamed this task from Make it possible to use if without else (because CachingParser doesn't support empty if) to Allow ifs without else and reject empty conditions (because CachingParser doesn't support empty if).Aug 19 2019, 3:23 PM

Change 530910 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/tools/codesniffer@master] Allow consecutive single-line comments not to start with a single space

https://gerrit.wikimedia.org/r/530910

Daimona claimed this task.Aug 19 2019, 5:21 PM
Daimona removed a project: Patch-For-Review.

Change 530910 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/tools/codesniffer@master] Allow consecutive single-line comments not to start with a single space
https://gerrit.wikimedia.org/r/530910

Whoops, wrong task. Gonna give it a try anyway.

Change 531259 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/AbuseFilter@master] Allow if without else

https://gerrit.wikimedia.org/r/531259

Deprecating and removing empty statements will be handled in T156096.

Change 531259 merged by jenkins-bot:
[mediawiki/extensions/AbuseFilter@master] Allow if without else

https://gerrit.wikimedia.org/r/531259

Daimona closed this task as Resolved.Aug 21 2019, 8:30 AM
Daimona removed a project: Patch-For-Review.