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

Missing compiler error on using 0T for time calculations #7578

Open NKarolak opened 10 months ago

NKarolak commented 10 months ago

1. Describe the bug When using 0T for time calculations, a compile error is missing to avoid a runtime error in BC.

2. To Reproduce Steps to reproduce the behavior:

Write this code - it does not raise a warning or error:

    local procedure TimeTest()
    var
        MillisecondsSinceMidnight: Integer;
    begin
        MillisecondsSinceMidnight := Time - 0T;
        Message(Format(MillisecondsSinceMidnight));
    end;

But when we run it in the client, we get the following runtime error:

The date is not valid.

Why date, I don't know ... this is something for the platform team ;-)

However, the correct code would have been:

    local procedure TimeTest()
    var
        MillisecondsSinceMidnight: Integer;
    begin
        MillisecondsSinceMidnight := Time - 000000T;
        Message(Format(MillisecondsSinceMidnight));
    end;

3. Expected behavior Raise a compiler error on calculating with 0T. The error should instruct to use 000000T instead.

4. Actual behavior No warning or error.

5. Versions:

NKarolak commented 9 months ago

This looks like it has been overlooked, @BazookaMusic - can you help/forward?

BazookaMusic commented 9 months ago

@NKarolak Oops, thanks for the ping!We should triage this. It should either fail compilation or we should make it work.

NKarolak commented 8 months ago

Just FYI, related standard issue but in AL code https://github.com/microsoft/BCApps/pull/444

rdebath commented 7 months ago

Just to highlight here; 0T and 00T are different valid values, neither should fail compilation as the values format to an empty string and midnight respectively. Noticing that the constant NULL time should not be used in a subtraction would be a nice Codecop error though.