alliedmodders / sourcepawn

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

"unknown array size" compilation error with indexing dynamically sized arrays of enum-structs. #937

Closed assyrianic closed 11 months ago

assyrianic commented 11 months ago
stock bool LibModSys_GetModulesByPriority(ManagerID id, PluginModule[] modules, int num_modules) {
    ...
            } else if( modules[n].priority < modules[i].priority ) {
                /// highest priority is first index.
                PluginModule tmp; tmp = modules[i];
                modules[i] = modules[n]; /// <--- error???
                modules[n] = tmp;
            }
}
SourcePawn Compiler 1.12.0.7092
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2021 AlliedModders LLC

./include/libmodsys.inc(236) : error 046: unknown array size (variable "modules")
   236 |                 modules[i] = modules[n];
------------------------^

./include/libmodsys.inc(237) : error 046: unknown array size (variable "modules")
   237 |                 modules[n] = tmp;
------------------------^

./include/libmodsys.inc(265) : error 046: unknown array size (variable "modules")
   265 |             modules[has_component++] = pl;
-------------------------------------^

./include/libmodsys.inc(294) : error 046: unknown array size (variable "modules")
   294 |             modules[has_group++] = pl;
---------------------------------^

./include/libmodsys.inc(323) : error 046: unknown array size (variable "modules")
   323 |             modules[has_flags++] = pl;
---------------------------------^
assyrianic commented 11 months ago

just reproduced it with this smaller example:

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
    name        = "",
    author      = "",
    description = "",
    version     = "0.0.0",
    url         = ""
};

enum struct I {
    int t;
}

stock void Sort(I[] is, int len) {
    for( int i; i < len; i++ ) {
        for( int n; n < len; n++ ) {
            if( i==n ) {
                continue;
            } else if( is[n].t < is[i].t ) {
                I tmp; tmp = is[i];
                is[i] = is[n];
                is[n] = tmp;
            }
        }
    }
}

public void OnPluginStart() {

}
SourcePawn Compiler 1.12.0.7092
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2021 AlliedModders LLC

test_compile.sp(23) : error 046: unknown array size (variable "is")
    23 |                is[i] = is[n];
-------------------^

test_compile.sp(24) : error 046: unknown array size (variable "is")
    24 |                is[n] = tmp;
-------------------^

2 Errors.