Skip to content

Commit

Permalink
Add Length validation to Rule0075 (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv authored Dec 18, 2024
1 parent c7d8adc commit 6c0d811
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions BusinessCentral.LinterCop.Test/Rule0075.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void Setup()
[Test]
[TestCase("ImplicitConversiontCodeToEnum")]
[TestCase("ImplicitConversiontEnumToAnotherEnum")]
[TestCase("RecordGetCodeFieldLengthTooLong")]
[TestCase("RecordGetGlobalVariable")]
[TestCase("RecordGetLocalVariable")]
[TestCase("RecordGetMethod")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure(ItemNo: Code[20]; VariantCode: Code[20])
var
ItemVariant: Record "Item Variant";
begin
[|ItemVariant.Get(ItemNo, VariantCode)|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,18 @@ private bool AreFieldCompatible(IArgument argument, IFieldSymbol field)
if (argumentNavType == NavTypeKind.Enum && fieldNavType == NavTypeKind.Enum)
return argumentType.OriginalDefinition == fieldType.OriginalDefinition;

if (argumentNavType == fieldNavType ||
argumentNavType == NavTypeKind.None ||
argumentNavType == NavTypeKind.Joker)
if ((argumentNavType == fieldNavType && argumentType.Length == fieldType.Length) ||
argumentNavType == NavTypeKind.None ||
argumentNavType == NavTypeKind.Joker)
return true;

if (ImplicitConversions.TryGetValue(argumentNavType, out var compatibleTypes) && !compatibleTypes.Contains(fieldNavType))
return false;

if (argumentType.Length > 0 && fieldType.Length > 0 &&
argumentType.Length > fieldType.Length)
return false;

return true;
}

Expand Down

0 comments on commit 6c0d811

Please sign in to comment.