diff --git a/compiler/messages.h b/compiler/messages.h index fd746b0cd..e3600e8ab 100644 --- a/compiler/messages.h +++ b/compiler/messages.h @@ -159,7 +159,7 @@ static const char* errmsg[] = { /*132*/ "cannot coerce non-object type %s to object type %s\n", /*133*/ "cannot coerce unrelated object types %s and %s\n", /*134*/ "type mismatch (expected \"%s\", got \"%s\")\n", - /*135*/ "cannot use enum struct type \"%s\" in natives\n", + /*135*/ "unused135\n", /*136*/ "reference is redundant, enum struct types are array-like\n", /*137*/ "cannot mix reference and array types\n", /*138*/ "const was specified twice\n", diff --git a/compiler/name-resolution.cpp b/compiler/name-resolution.cpp index 2e3adf638..222c5d96a 100644 --- a/compiler/name-resolution.cpp +++ b/compiler/name-resolution.cpp @@ -821,10 +821,6 @@ FunctionDecl::BindArgs(SemaContext& sc) } Type* type = typeinfo.type; - if (type->isEnumStruct()) { - if (is_native_) - report(var->pos(), 135) << type; - } /* Stack layout: * base + 0*sizeof(cell) == previous "base" diff --git a/tests/compile-only/fail-enum-struct-in-native.sp b/tests/compile-only/fail-enum-struct-in-native.sp deleted file mode 100644 index e0a063923..000000000 --- a/tests/compile-only/fail-enum-struct-in-native.sp +++ /dev/null @@ -1,10 +0,0 @@ -enum struct Point { - int x; - int y; -} - -native void Invalid(Point p); - -public main() -{ -} diff --git a/tests/compile-only/fail-enum-struct-in-native.txt b/tests/compile-only/fail-enum-struct-in-native.txt deleted file mode 100644 index adb4bc164..000000000 --- a/tests/compile-only/fail-enum-struct-in-native.txt +++ /dev/null @@ -1 +0,0 @@ -(6) : error 135: cannot use enum struct type "Point" in natives diff --git a/tests/enum-structs/native-access.out b/tests/enum-structs/native-access.out new file mode 100644 index 000000000..47a03a3fd --- /dev/null +++ b/tests/enum-structs/native-access.out @@ -0,0 +1,2 @@ +x: 5 +y: 10 diff --git a/tests/enum-structs/native-access.sp b/tests/enum-structs/native-access.sp new file mode 100644 index 000000000..512f3091a --- /dev/null +++ b/tests/enum-structs/native-access.sp @@ -0,0 +1,8 @@ +#include + +public void main() { + TestStruct ts; + ts.x = 5; + ts.y = 10; + print_test_struct(ts); +} diff --git a/tests/shell.inc b/tests/shell.inc index 43db54ac6..ddb4b3207 100644 --- a/tests/shell.inc +++ b/tests/shell.inc @@ -2,6 +2,11 @@ #include #include +enum struct TestStruct { + int x; + int y; +} + native void printnum(int n); native void writenum(int n); native void printfloat(float n); @@ -45,3 +50,5 @@ native void copy_2d_array_to_callback(const int[] flat_array, int length, int st Array2dCallback callback); native void assert_eq(any a1, any a2); + +native void print_test_struct(TestStruct x); diff --git a/vm/shell/shell.cpp b/vm/shell/shell.cpp index 385de977b..d7ab6ad14 100644 --- a/vm/shell/shell.cpp +++ b/vm/shell/shell.cpp @@ -308,6 +308,25 @@ static cell_t Copy2dArrayToCallback(IPluginContext* cx, const cell_t* params) return 0; } +#pragma pack(push, 1) +struct TestStruct { + cell_t x; + cell_t y; +}; +#pragma pack(pop) + +static cell_t PrintTestStruct(IPluginContext* cx, const cell_t* params) { + TestStruct* ts; + + int err; + if ((err = cx->LocalToPhysAddr(params[1], reinterpret_cast(&ts))) != SP_ERROR_NONE) + return cx->ThrowNativeErrorEx(err, "Could not read argument 1"); + + printf("x: %d\n", ts->x); + printf("y: %d\n", ts->y); + return 0; +} + class DynamicNative : public INativeCallback { public: @@ -366,6 +385,7 @@ static int Execute(const char* file) BindNative(rt, "call_with_string", CallWithString); BindNative(rt, "assert_eq", AssertEq); BindNative(rt, "printf", Printf); + BindNative(rt, "print_test_struct", PrintTestStruct); IPluginFunction* fun = rt->GetFunctionByName("main"); if (!fun)