StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
77 stars 31 forks source link

LC0051 - Wrong overflow error #521

Closed epernst closed 8 months ago

epernst commented 8 months ago

We have a line that is giving an LC0051 error (Possible overflow assigning 'Text' to 'Code[20]'), where it shouldn't:

Dimension.SetFilter(Code, '%1', '@' + Rec.Code + '*');

The filter in SetFilter is a text without length and should not give this error. Had it been a SetRange, then it should give it. But not here.

Arthurvdv commented 8 months ago

image

Is the Rec.Code is a Code[20] field? In that case I believe when that fields contains a value of 20 characters, you'll get runtime error. Otherwise can you provide a small code sample for a repo?

epernst commented 8 months ago

Yes, the Rec.Code is a code[20] and gives me the error. But it shouldn't, as an filter can be as long as you need it to be.

var Dimension: Record Dimension; RecCode: Code[20]; begin Dimension.SetFilter(Code, '%1', '@' + RecCode + '*'); end;

Arthurvdv commented 8 months ago

I'm probably doing something wrong here? Tested this with the example below, which throws me an runtime error.

pageextension 50100 "My Customer List" extends "Customer List"
{
    trigger OnOpenPage()
    var
        Dimension: Record Dimension;
        RecCode: Code[20];
    begin
        RecCode := 'ABCDEFGHIJKLMNOPQRST'; // Fill variable with 20 characters
        Dimension.SetFilter(Code, '%1', '@' + RecCode + '*');
    end;
}

image

epernst commented 8 months ago

I have copied this "pattern" from Microsoft, where it's used many places, so I'm a bit surprised that you're right!

Arthurvdv commented 8 months ago

In most cases of the Code field with masterdata, like Customers, Dimensions, etc, you're not easily going to hit this limit I believe.

Only in rare occasions where the setup of dimension value codes is like PROJ-WEU-2024-EUR-05 you're out of luck ;-)