AL icon indicating copy to clipboard operation
AL copied to clipboard

Event Subscriber with other Signature than Publisher (var can be omitted)

Open FWI-95 opened this issue 3 years ago • 4 comments

1. Describe the bug Omitting the var attribute in Event Subscribers overwrites the Publisher attribute.

Example AL File : An event with a Boolean "Handled" argument passed by reference is subscribed with an event which has the handled parameter as pass by value.

2. To Reproduce see example file or here:

codeunit 53000 EventPublisher
{
    trigger OnRun()
    var
        VarNonVarHandled: Boolean;
    begin
        VarNonVarEvent(VarNonVarHandled);

         message(format(VarNonVarHandled));
    end;

    [IntegrationEvent(false, false)]
    local procedure VarNonVarEvent(var Handled: Boolean)
    begin
    end;
}

codeunit 53001 EventSubscriber
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::EventPublisher, VarNonVarEvent, '', false, false)]
    local procedure VarNonVarEvent(Handled: Boolean);
    begin
        Handled := true;
    end;
}

3. Expected behavior Compiler does not accept or at least warns about the signature mismatch

4. Actual behavior The handled parameter content is not changed by the event subscriber

5. Versions:

  • AL Language: v11.0.787898
  • Visual Studio Code: 1.78.2
  • Business Central: v22 (2023 wave 1)

FWI-95 avatar May 24 '23 16:05 FWI-95

A warning may be worth it in this case.

BazookaMusic avatar May 25 '23 09:05 BazookaMusic

I would also appreciate a warning. It seems that leaving parameters altogether is a possibility, although I'm uncertain if this is by design. image

SKnoppers avatar May 31 '23 20:05 SKnoppers

That might be a breaking change for some of our users, I would suggest you go ahead and post this to our ideas forum at https://aka.ms/BusinessCentralideas, or vote up the idea if its already there. We're constantly monitoring top Ideas and will consider them for a future release.

PooyaKharamesh avatar Jun 08 '23 11:06 PooyaKharamesh

Why would a compiler warning be a breaking change?

But yes I will. Thank you

FWI-95 avatar Jun 08 '23 11:06 FWI-95