Event Subscriber with other Signature than Publisher (var can be omitted)
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)
A warning may be worth it in this case.
I would also appreciate a warning. It seems that leaving parameters altogether is a possibility, although I'm uncertain if this is by design.
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.
Why would a compiler warning be a breaking change?
But yes I will. Thank you