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

Fix some type checking regressions. #990

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ Expr* Semantics::CheckArgument(CallExpr* call, ArgDecl* arg, Expr* param,
// If the input type is an index into an array, create an implicit
// array type to represent the slice.
Type* type = val->type();
if (val->ident == iARRAYCELL || val->ident == iARRAYCHAR)
if ((val->ident == iARRAYCELL || val->ident == iARRAYCHAR) && !type->isEnumStruct())
type = types_->defineArray(type, 0);

TypeChecker tc(param, arg->type(), type, TypeChecker::Argument);
Expand Down
2 changes: 2 additions & 0 deletions compiler/type-checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ bool TypeChecker::CheckArrays(ArrayType* formal, ArrayType* actual) {
}
if (formal_elt->isAny() && actual_elt->hasCellSize())
return true;
if (actual_elt->isAny() && formal_elt->hasCellSize())
return true;
}

return DiagnoseFailure();
Expand Down
20 changes: 20 additions & 0 deletions tests/compile-only/ok-inner-enum-struct-to-any.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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[]
}
50 changes: 49 additions & 1 deletion tests/sourcemod/include/testing.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ stock void SetTestContext(const char[] context)
strcopy(TestContext, sizeof(TestContext), context);
}

stock void AssertEq(const char[] text, int cell1, int cell2)
stock void AssertEq(const char[] text, any cell1, any cell2)
{
TestNumber++;
if (cell1 == cell2)
Expand All @@ -52,6 +52,39 @@ stock void AssertEq(const char[] text, int cell1, int cell2)
}
}

stock void AssertArrayEq(const char[] text, const any[] value, const any[] expected, int len)
{
TestNumber++;
for (int i = 0; i < len; ++i)
{
if (value[i] != expected[i])
{
PrintToServer("[%d] %s FAIL: %s should be %d at index %d, got %d", TestNumber, TestContext, text, expected[i], i, value[i]);
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
break;
}
}
PrintToServer("[%d] %s: '%s' arrays are equal OK", TestNumber, TestContext, text);
}

stock void AssertArray2DEq(const char[] text, const any[][] value, const any[][] expected, int len, int innerlen)
{
TestNumber++;
for (int i=0; i < len; ++i)
{
for (int j=0; j < innerlen; ++j)
{
if (value[i][j] != expected[i][j])
{
PrintToServer("[%d] %s FAIL: %s should be %d at index [%d][%d], got %d", TestNumber, TestContext, text, expected[i][j], i, j, value[i][j]);
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
break;
}
}
}
PrintToServer("[%d] %s: '%s' 2D arrays are equal OK", TestNumber, TestContext, text);
}

stock void AssertFalse(const char[] text, bool value)
{
TestNumber++;
Expand Down Expand Up @@ -93,3 +126,18 @@ stock void AssertStrEq(const char[] text, const char[] value, const char[] expec
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
}
}

stock void AssertStrArrayEq(const char[] text, const char[][] value, const char[][] expected, int len)
{
TestNumber++;
for (int i = 0; i < len; ++i)
{
if (!StrEqual(value[i], expected[i]))
{
PrintToServer("[%d] %s FAIL: %s should be '%s' at index %d, got '%s'", TestNumber, TestContext, text, expected[i], i, value[i]);
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
break;
}
}
PrintToServer("[%d] %s: '%s' arrays are equal OK", TestNumber, TestContext, text);
}
Loading
Loading