From 5d7dab6740d80cb7866bab82e92b57acdfd08679 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Fri, 27 Nov 2026 06:08:53 +0100 Subject: [PATCH 1/2] docs(LC0096): document non-reports and the overload migration route Co-Authored-By: Claude Fable 5.1 --- content/docs/analyzers/LinterCop/LC0096.md | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/content/docs/analyzers/LinterCop/LC0096.md b/content/docs/analyzers/LinterCop/LC0096.md index 3fa7493..f591395 100644 --- a/content/docs/analyzers/LinterCop/LC0096.md +++ b/content/docs/analyzers/LinterCop/LC0096.md @@ -99,10 +99,12 @@ The rule suppresses the diagnostic in several cases where the parameter is inten - **Different module**: when the target method is defined in a different module, the developer cannot refactor the external signature. - **Built-in methods**: calls to built-in methods (`Clear`, `Page.RunModal`, etc.) are excluded. - **Different variable or field access**: `Customer.DoSomething(Customer2)` or `Customer.DoSomething(Customer."No.")` are not flagged because the argument is not the same record instance. +- **`xRec` arguments**: `Rec.AssistEdit(xRec)` or `DoSomething(xRec)` passes the previous version of the record, a deliberate pattern whose need the callee decides; only `xRec.DoSomething(xRec)` is flagged. +- **`RecordRef` arguments**: a `RecordRef` is its own buffer, not `Rec`, even after `RecRef.GetTable(Rec)`, so passing it is never redundant. ### Edge case: local method called with multiple record instances -A local procedure that takes a record parameter may be called with several different record instances — some of them `Rec`. The diagnostic still fires on the `Rec` call. The usual fix — invoke the method on the record instead (`Other.DoSomething()`) — does not apply here: it would force the local procedure to become public or internal for no reason other than satisfying the rule. +A local procedure that takes a record parameter may be called with several different record instances — some of them `Rec`. The diagnostic still fires on the `Rec` call, but the other callers still need the parameter. {{< highlight al "hl_lines=13" >}} table 50100 MyTable @@ -120,15 +122,15 @@ table 50100 MyTable DoSomething(Rec); // Unnecessary record parameter in method call [LC0096] end; - local procedure DoSomething(MyTable: Record MyTable) + local procedure DoSomething(var MyTable: Record MyTable) begin end; } {{< /highlight >}} -Add a parameterless overload that assigns `Rec` to a local variable and delegates to the parameterized procedure. The delegating call passes a local variable, not `Rec`, so the diagnostic no longer fires — and the call site no longer implicitly passes the same record twice. The cost is one extra local variable and a record copy. +Invert the delegation: move the implementation into a parameterless procedure that works on `Rec`, and let the procedure with the parameter call it on that parameter. `MyTable.DoSomething()` passes no argument, so the diagnostic no longer fires, and a `var` parameter keeps referring to the caller's record. A `local` procedure cannot be called on another record instance, so both procedures become `internal`, which still keeps them inside your app. -{{< highlight al "hl_lines=13 16-22" >}} +{{< highlight al "hl_lines=13 16-19 21-24" >}} table 50100 MyTable { fields @@ -144,16 +146,40 @@ table 50100 MyTable DoSomething(); end; - local procedure DoSomething() - var - MyTable: Record MyTable; + internal procedure DoSomething() + begin + // implementation, using Rec + end; + + internal procedure DoSomething(var MyTable: Record MyTable) + begin + MyTable.DoSomething(); + end; +} +{{< /highlight >}} + +Once no caller needs the procedure with the parameter any more, delete it. + +If the procedure must stay `local` and takes the record by value, a parameterless overload can instead assign `Rec` to a local variable and pass that (`MyTable := Rec; DoSomething(MyTable);`). Do not use this copy for a `var` parameter: the callee would change the local copy, not `Rec`. + +### Public procedures and dependent apps + +Removing the record parameter from a public procedure changes its signature, which breaks every app that depends on yours; AppSourceCop reports it as [AS0024](https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0024). Use the same inverted delegation and mark the procedure with the parameter as obsolete, so dependent apps can move to the new overload over a release cycle before you remove it: + +{{< highlight al "hl_lines=8-12" >}} +table 50100 MyTable +{ + procedure DoSomething() begin - MyTable := Rec; - DoSomething(MyTable); + // implementation, using Rec end; - local procedure DoSomething(MyTable: Record MyTable) + [Obsolete('Replaced by the overload without the record parameter.')] + procedure DoSomething(var MyTable: Record MyTable) begin + MyTable.DoSomething(); end; } {{< /highlight >}} + +For a `local` procedure there are no outside callers: remove the parameter directly, or delete the procedure with the parameter once your own callers no longer need it. From 84c899fe0c0e46c2863d2701199dd0b467fabdb8 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Fri, 27 Nov 2026 06:13:53 +0100 Subject: [PATCH 2/2] docs(LC0096): mention the optional obsolete tag Co-Authored-By: Claude Fable 5.1 --- content/docs/analyzers/LinterCop/LC0096.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/docs/analyzers/LinterCop/LC0096.md b/content/docs/analyzers/LinterCop/LC0096.md index f591395..3baa9ac 100644 --- a/content/docs/analyzers/LinterCop/LC0096.md +++ b/content/docs/analyzers/LinterCop/LC0096.md @@ -182,4 +182,6 @@ table 50100 MyTable } {{< /highlight >}} +The tag argument of the attribute is optional. Apps that run AppSourceCop add the version in which the procedure became obsolete, as [AS0073](https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0073) requires. + For a `local` procedure there are no outside callers: remove the parameter directly, or delete the procedure with the parameter once your own callers no longer need it.