AL icon indicating copy to clipboard operation
AL copied to clipboard

Missing compiler error on using 0T for time calculations

Open NKarolak opened this issue 2 years ago • 4 comments

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:

  • AL Language: 12.1.887908
  • Visual Studio Code: 1.84.1
  • Business Central: 23.0

NKarolak avatar Nov 09 '23 08:11 NKarolak

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

NKarolak avatar Dec 15 '23 20:12 NKarolak

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

BazookaMusic avatar Dec 15 '23 22:12 BazookaMusic

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

NKarolak avatar Dec 20 '23 13:12 NKarolak

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.

rdebath avatar Jan 23 '24 13:01 rdebath