microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
737 stars 243 forks source link

AA0181 rule warning for Codeunit.Find method #7731

Closed RadoArvay closed 3 months ago

RadoArvay commented 5 months ago

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:

Internal work item: AB#534244

EmilDamsbo commented 5 months ago

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
NKarolak commented 5 months ago

@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.

RadoArvay commented 5 months ago

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

EmilDamsbo commented 5 months ago

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

sergiusignacius commented 4 months ago

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!

JesperSchulz commented 3 months ago

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/