microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
728 stars 241 forks source link

Procedure declaration should not end with semicolon #7598

Closed Arthurvdv closed 8 months ago

Arthurvdv commented 9 months ago

1. Describe the bug There are two actions in the AL Language VS Code extension, where I'm aware of, that add an semicolon at the ending of a Procedure declaration.

A) 'Subscribe to Event' (AL Explorer) B) 'Implement interface' code action

2. To Reproduce (A) - 'Subscribe to Event' (AL Explorer) From the AL Explorer select the tab EVENTS. Select an event and hit the Subscribe button. Paste the content of the clipboard in an AL file

image image

    [EventSubscriber(ObjectType::Codeunit, Codeunit::Checklist, 'OnChecklistLoading', '', false, false)]
    local procedure Checklist_OnChecklistLoading();
    begin
    end;

The semicolon at the ending of Checklist_OnChecklistLoading procedure should not be there.

2. To Reproduce (B) - 'Implement interface' code action Create an codeunit which implements an interface Select the 'Implement interface' code action

image image

interface MyInterface
{
    procedure Myprocedure()
}

codeunit 50100 MyCodeunit implements MyInterface
{
    procedure Myprocedure();
    begin

    end;
}

The semicolon at the ending of Myprocedure procedure should not be there.

fvet commented 9 months ago

Same applies to the 'Find Event' (probably uses the same code path as the 'Subscribe to Event' scenario)

FindEvent

bjarkihall commented 9 months ago

Not part of the bug itself, but the event name, in this case 'OnChecklistLoading', can also skip the single-quotes, which has been recommended since BC 22 - if it's just a matter of updating the code-snippet used for the event generation. :)

RadoArvay commented 9 months ago

But just a simple question about a semicolon: why not?

fvet commented 9 months ago

But just a simple question about a semicolon: why not?

There's some valid arguments listed here on X https://twitter.com/arthrvdv/status/1727729430737342791

NKarolak commented 9 months ago

@fvet Please mind that people who are not logged into Twitter / X cannot read any of the answers below, thanks to Elon.

Arthurvdv commented 9 months ago

I’ve try’ed to summarize all the reasons in the documentation on the rule of the LinterCop; https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0024

So based on the documentation, syntactically the ";" is not something that ends a statement in (Pasc)AL, but it actually is a separator symbol to separate statements. That's why procedure declaration should not end with semicolon and also the reason why you can omit it for the last statement.

SBalslev commented 8 months ago

We'll se what we can do about the snippets and the copy event subscriber but no other changes. The separator remains a valid syntax.