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
718 stars 242 forks source link

[Pre-release] Feedback/question about the new "is" operator #7780

Closed dannoe closed 1 week ago

dannoe commented 1 week ago

I discovered the new is operator in the prerelease version and have a question. Is it intended that the syntax is designed so it is only valid for interfaces.

I think this might make it hard to add other is-checks in the future, e.g.:

procedure Foo(MyVariant: Variant)
begin
    if MyVariant is Record "Item" then
        Message('MyVariant is a Item');
end;

Or maybe is-casts like in c#:

procedure Foo(MyVariant: Variant)
var
  MyItem: Record "Item"
begin
    if MyVariant is MyItem then
        Message('Item: ' + MyItem."No.");
end;
esbenk commented 1 week ago

It is targeted interfaces for now, but we don't rule out expanding the functionality in the future. We would probably then use then existing ObjectType qualifier syntax e.g.

procedure Foo(MyVariant: Variant)
begin
    if MyVariant is Database::"Item" then
        Message('MyVariant is a Item');
end;

And yes I know that our current Database:: is a weird naming, but it is what we have today. We have discussed adding Table:: at some point.