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
750 stars 247 forks source link

Can't overload a procedure with integers and Enums #5853

Open salgiza opened 4 years ago

salgiza commented 4 years ago

Describe the bug You can't declare these two methods in the same codeunit:

procedure MyMethod(X: Integer); procedure MyMethod(X: Enum MyEnum);

Or even these two methods: procedure MyMethod(X: Option); procedure MyMethod(X: Enum MyEnum);

Note: if you are wondering, I was migrating an app that has been upgraded from using options to enums. Having both methods was intended to keep compatibility with previous customers.

To Reproduce Just declare two procedures with the same name in a Codeunit, one with a single Integer param and the other with a single Enum param. The AL compiler thinks that both procedures are the same.

Expected behavior The AL compiler should have detected a different signature and use the Enum method if called with an Enum of that Type, and the Integer procedure otherwise.

Screenshots

5. Versions:

dzzzb commented 4 years ago

I wonder though if this is because implicit conversions are currently only deprecated, not disallowed.

atoader commented 4 years ago

Hi! As things stand right now, you would get an ambiguous overload in certain cases. Whenever using overloads, keep in mind that the conversion matrix for AL contains a lot of tricky cases for backwards compatibility which might lead to unexpected behavior.

fvet commented 3 years ago

Encoutered the same when refactoring some of our functions from options to enums (as a reference https://www.yammer.com/dynamicsnavdev/#/threads/show?threadId=1156165716639744).

AL Compiler must include a CodeCop to at least alert or auto-resolve conversions, since now we unintentionally introduce new breaking changes for all dependent extensions. With the introduction of the new overload functions, extensions fail to compile and get warning below

The call is ambiguous between the method 'xxx(Option)' and the method 'xxx(Enum "My Enum")'

pri-kise commented 3 years ago

For my extension I had an even more annoying problem. I'm able to compile the package in VS Code and I'm getting no error. But as soon as i try to publish the extension I receive this error. That's why i think that this issue should being marked as bug and not only as enhancement.

The call is ambiguous between the method ....