diff --git a/backend.native/tests/interop/basics/cstructs.def b/backend.native/tests/interop/basics/cstructs.def index 7535243dcb7..524f1b383eb 100644 --- a/backend.native/tests/interop/basics/cstructs.def +++ b/backend.native/tests/interop/basics/cstructs.def @@ -1,3 +1,4 @@ +nonStrictEnums = NonStrict --- typedef struct { int i; @@ -7,20 +8,31 @@ enum E { R, G, B }; +enum NonStrict { + N, S, K +}; + struct Complex { unsigned int ui; Trivial t; struct Complex* next; enum E e; + enum NonStrict nonStrict; int arr[2]; }; +struct __attribute__((packed)) Packed { + int i : 1; + enum E e : 2; +}; + struct Complex produceComplex() { struct Complex complex = { .ui = 128, .t = {1}, .next = 0, .e = R, + .nonStrict = K, .arr = {-51, -19} }; return complex; diff --git a/backend.native/tests/interop/basics/structs.kt b/backend.native/tests/interop/basics/structs.kt index 4057db967d9..e5b720a0e0f 100644 --- a/backend.native/tests/interop/basics/structs.kt +++ b/backend.native/tests/interop/basics/structs.kt @@ -23,11 +23,49 @@ fun main() { e = E.G assertEquals(e, E.G) + assertEquals(K, nonStrict) + nonStrict = S + assertEquals(S, nonStrict) + assertEquals(arr[0], -51) assertEquals(arr[1], -19) arr[0] = 51 arr[1] = 19 assertEquals(arr[0], 51) assertEquals(arr[1], 19) + + // Check that subtyping via Nothing-returning functions does not break compiler. + assertFailsWith { + ui = TODO() + t.i = TODO() + next = TODO() + e = TODO() + nonStrict = TODO() + } } + memScoped { + val packed = alloc() + packed.i = -1 + assertEquals(-1, packed.i) + packed.e = E.R + assertEquals(E.R, packed.e) + // Check that subtyping via Nothing-returning functions does not break compiler. + assertFailsWith { + packed.i = TODO() + packed.e = TODO() + } + } + // Check that generics doesn't break anything. + checkEnumSubTyping(E.R) + checkIntSubTyping(630090) +} + +fun checkEnumSubTyping(e: T) = memScoped { + val s = alloc() + s.e = e +} + +fun checkIntSubTyping(x: T) = memScoped { + val s = alloc() + s.i = x } \ No newline at end of file