Error when attempting to pass nested enum struct property to parameters of type `any[]`
Using the SourcePawn Compiler 1.12.0.7140, attempting to pass an enum struct property that also is an enum struct to a function expecting any[] will throw a "no viable conversion" error. Sorry for the terrible title, but I've attached an example to illustrate:
enum struct InnerStruct
{
int num;
}
enum struct OuterStruct
{
InnerStruct inner;
}
public void OnPluginStart()
{
OuterStruct myStruct;
Test(myStruct.inner);
}
void Test(any[] arr)
{
// no viable conversion from InnerStruct[] to any[]
}
Output:
spcomptest.sp(14) : error 450: no viable conversion from "InnerStruct[]" to "any[]"
14 | Test(myStruct.inner);
------------------------------^
This seems to be specifically an issue with nested enum structs as this still works:
OuterStruct myStruct;
Test(myStruct);
This might be related. Passing this into an any[] param causes error 035: argument type mismatch (argument 1). I found it by compiling a plugin doing Call_PushArrayEx(this, sizeof(this), SM_PARAM_COPYBACK) inside a struct's member function.
enum struct A
{
int i;
void InnerTest()
{
OuterTest(this); // error 035: argument type mismatch (argument 1)
}
}
void OuterTest(any[] arr) { }
public void OnPluginStart()
{
A arr;
OuterTest(arr);
}
Thanks for the test case... I'm in the midst of a very big refactoring to remove matchtag(), which I'm hoping will lead a world where these kinds of issues are easy to fix and difficult to regress.
I'm not sure if this is the same issue, or something different, but the SourceMod testsuite fails with a similar error when pointing at current latest SourcePawn.
Compiling test_sorting.sp
SourcePawn Compiler 1.13.0.1
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2021 AlliedModders LLC
../sourcemod/plugins/testsuite/mock/test_sorting.sp(108) : error 450: no viable conversion from "any[10]" to "int[]"
108 | SortCustom1D(view_as<any>(floatArray), sizeof(floatArray), Custom1DSortFloat);
--------------------------^
1 Error.
https://github.com/alliedmodders/sourcemod/actions/runs/11532714757/job/32104813488?pr=2211
These would be much cleaner to fix with the IR stuff all done, but alas, it's too important to leave broken forever.
Fixed on master now.