AL icon indicating copy to clipboard operation
AL copied to clipboard

AA0181 rule warning for Codeunit.Find method

Open RadoArvay opened this issue 1 year ago • 5 comments

There is a codeunit with Find(var RecordVariable: Record SomeRecord): Boolean method defined in my code. When I use it like

if CodeunitVariable.Find(RecordVariable) then;

or

CodeunitVariable.Find(RecordVariable)

I am getting warning AA0181: The FindSet() or Find() method on the record 'SomeRecord' must be used only in connection with the Next() method.

Note: If the call is repeated on multiple lines, the warning appears only on the last line of code.

Maybe there is a relation to #7459.

Versions:

  • AL Language: v13.0.971907
  • Visual Studio Code: 1.88.1

Internal work item: AB#534244

RadoArvay avatar Apr 25 '24 12:04 RadoArvay

I think the issue is lacking come context for what is the issue. According to the public documentation about this analyzer rule, the scenario sounds like it is by design. Can you provide further details on

  1. What behaviour your were not expecting
  2. What you were expecting,
  3. A code snippet with proper context

EmilDamsbo avatar Apr 26 '24 09:04 EmilDamsbo

@EmilDamsbo I was mistaken on first read as well, but: The rule should warn for Record.Find only. But it also gives false positives on Codeunit.Find, whereas Find in the latter case is a custom procedure, not the AL method.

NKarolak avatar Apr 26 '24 09:04 NKarolak

@EmilDamsbo Do you still need any other details? Please read the description again; I think there is all you need.

RadoArvay avatar Apr 26 '24 11:04 RadoArvay

Thanks both, I misread the original issue. Seems this has been correctly tagged now

EmilDamsbo avatar May 01 '24 11:05 EmilDamsbo

It does seem like we're incorrectly emitting AA0181 on signatures that resemble the .Find method on records.

Here's a repro:

codeunit 50109 MyCodeunitA
{
    procedure Find(rec: Record Customer): Boolean
    begin
        exit(true);
    end;
}


codeunit 50110 MyCodeunitB
{

    procedure Test(cu: Codeunit MyCodeunitA; r: Record Customer)
    begin
        if cu.Find(r) then
            Message('Found');
    end;
}

AA0181 is emitted on cu.Find(r). Approving the bug. Thank you for reporting it!

sergiusignacius avatar May 07 '24 07:05 sergiusignacius

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 25.0.20197.0 and VS Code Extension Version 14.0.1032641.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://freddysblog.com/2020/06/25/working-with-artifacts/

JesperSchulz avatar Jun 07 '24 09:06 JesperSchulz