Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function type incorrectly initialized to 0 on enum structs #469

Closed
Sikarii opened this issue Apr 16, 2020 · 2 comments
Closed

Function type incorrectly initialized to 0 on enum structs #469

Sikarii opened this issue Apr 16, 2020 · 2 comments
Labels
bug-future compiler Problems with the compiler parsing source code.

Comments

@Sikarii
Copy link

Sikarii commented Apr 16, 2020

When initializing a variable of type Function in an enum struct, they seem to incorrectly default to 0.

I believe the Function type in this case should default to -1 (INVALID_FUNCTION) instead.

The following code results in:

  • Is null: 1
  • Is INVALID_FUNCTION: 0
enum struct MyStruct
{
    Function Handler;
}

public void OnPluginStart()
{
    MyStruct myStruct;

    PrintToServer("Is null: %d", (!!myStruct.Handler));
    PrintToServer("Is INVALID_FUNCTION: %d", (myStruct.Handler != INVALID_FUNCTION));
}
@dvander
Copy link
Member

dvander commented Apr 16, 2020

Thanks for the report. This is an annoying case, because variables are supposed to be zero'd by default, but both 0 and -1 are invalid values for a function variable. It's way too late to fix the fact that we picked -1 for INVALID_FUNCTION.

I'm tempted to make the comparison implicitly check for both. Until I can finish the array refactoring PR, it's probably the easier route.

dvander added a commit that referenced this issue Sep 4, 2020
Bug: issue #469
Test: tests/compile-only/fail-old-any-decl.sp
@peace-maker peace-maker added the compiler Problems with the compiler parsing source code. label Mar 15, 2021
@dvander
Copy link
Member

dvander commented Oct 28, 2023

This is now zero/null.

@dvander dvander closed this as completed Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-future compiler Problems with the compiler parsing source code.
Projects
None yet
Development

No branches or pull requests

3 participants