Validate EventSubscriber parameter signatures against publisher overloads #359
Replies: 1 comment 2 replies
-
|
Hi @frottke, thanks for ceating an discussion here and it's looks at first site a great suggestion. Before we dig into the rule itself, I think something might not be quite right with the example, and I wanted to check with you rather than assume. When I take the
The two
To be clear, AL does support procedure overloading in general, so two regular procedures with the same name and different signatures are fine. But that doesn't seem to extend to event publishers: as soon as both same-named procedures are marked So a couple of questions, and it's entirely possible I'm missing something:
If you could share a minimal example that actually compiles and reproduces the ambiguity you're describing, that would help us a lot in understanding the exact situation and figuring out whether (and how) an analyzer rule could catch it. Thanks again for the raising an discussion here and looking forward to hearing more 🙋 |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Suggestion: Validate EventSubscriber parameter signatures against publisher overloads
Description
This suggestion is related to #145, but covers a different case.
Issue #145 asks for a warning for unused parameters in regular procedures. For EventSubscriber methods, unused parameters need to be handled more carefully. In an event subscriber, a parameter can be unused in the procedure body but still be required to identify the intended event publisher signature.
Therefore, this suggestion is not to warn about unused EventSubscriber parameters. Instead, it suggests a rule that validates whether the EventSubscriber parameter signature matches an existing event publisher signature exactly.
Problem
In AL, multiple event publisher procedures can have the same name but different parameter signatures. This effectively means that the event publisher name is overloaded.
If an EventSubscriber does not declare all parameters of the intended publisher because some of them are not used, the subscriber can accidentally match another publisher overload with the same event name. This can lead to the subscriber being attached to a different publisher location than intended.
Example
Problematic subscriber:
The subscriber is intended to run before
ApplyCampaignPrices, but it only declaresSalesHeader.Because another publisher overload exists with exactly this signature, the subscriber matches the one-parameter publisher instead of the intended campaign-specific publisher.
Expected subscriber:
Even if
CampaignNoandIsHandledare not used in the subscriber body, they are part of the intended publisher signature. Declaring them makes the subscription unambiguous.Suggested rule
For every method marked with
[EventSubscriber], resolve all matching event publishers by:Then compare the EventSubscriber method parameters with the available publisher signatures.
The EventSubscriber should use a parameter signature that exists as a publisher signature.
Diagnostic
Report a diagnostic when an EventSubscriber uses a parameter combination that cannot be matched clearly to exactly one existing publisher signature.
Suggested message:
Relation to unused parameter warnings
This rule should be separated from a general unused-parameter warning.
For regular procedures, unused parameters may be a code smell.
For EventSubscriber methods, unused parameters can be intentional and necessary because they define which overloaded event publisher signature is subscribed to.
Therefore, a general unused-parameter warning should either ignore EventSubscriber methods or treat them differently.
Beta Was this translation helpful? Give feedback.
All reactions