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
733 stars 243 forks source link

A `[TryFunction]` that implements an interface returns wrong values #7558

Open hemisphera opened 10 months ago

hemisphera commented 10 months ago

1. Describe the bug When a [TryFunction] implements an interface that requests a function that returns a Boolean, the return value, when used through the interface does not return the correct value.

2. To Reproduce Create the following interface:

interface ITest
{
    procedure DoTest(): Boolean;
}

Create the following Codeunit that implements this interface

codeunit 50100 Implementation implements ITest
{
    [TryFunction]
    procedure DoTest();
    begin
    end;
}

Note that DoTest does not explicitly return a value here, even though this is requested by the interface. Being a [TryFunction] though, this implicitly is the case and as such this compiles without problems.

Also note that DoTest does nothing and as such cannot raise an exception. This in turn means that the function must return true, being a [TryFunction].

Create the following test codeunit:

codeunit 50101 ImplementationTest
{

    Subtype = Test;

    var
        Assert: Codeunit "Library Assert";

    [Test]
    procedure RunText();
    var
        interface: Interface ITest;
        codeunit: Codeunit Implementation;
    begin
        Assert.IsTrue(codeunit.DoTest(), 'Codeunit failed');
        interface := codeunit;
        Assert.IsTrue(interface.DoTest(), 'Interface failed');
    end;
}

The assertion "Codeunit failed" does not fail - this is expected The assertion "Interface failed" on the other hand does.

3. Expected behavior I expect one of two things:

4. Actual behavior You can run the test codeunit and see what happens.

5. Versions: