alliedmodders / sourcepawn

A small, statically typed scripting language.
Other
369 stars 63 forks source link

Using enum as array size crashes compiler #939

Closed Vinillia closed 8 months ago

Vinillia commented 9 months ago

Code below seems valid but compiler throws "Internal error"

OS: Windows
SourceMod Version Information:
SourceMod Version: 1.12.0.7102
SourcePawn Engine: 1.12.0.7102, jit-x86 (build 1.12.0.7102)
SourcePawn API: v1 = 5, v2 = 16
Compiled on: Jan 22 2024 07:31:37
Built from: https://github.com/alliedmodders/sourcemod/commit/0bc9aa46
Build ID: 7102:0bc9aa46
http://www.sourcemod.net/
// by the SourceMod Dev Team

//// test.sp
// Internal error.

Press enter to exit ...
enum Pl0000
{
    Pl_MAX
}

enum struct Array
{
    int value[Pl_MAX];
}
dvander commented 8 months ago

Thanks for the test case. This doesn't crash for me anymore, but it does have terrible error messages. I've added a test case and cleaned up the diagnostics:

fail-array-decl-with-zero-enum-value.sp(8) : error 009: invalid array size (negative, zero or out of bounds)
     8 |     int value[Pl_MAX];
-----------------------^