Open Et7f3 opened 2 years ago
The problem is that, without the tag, there's not always enough information available to retrieve the layout. As the generated code displayed in the error message suggests:
16 | | Struct ({ tag = ""; _} as s'), "v2" ->
ctypes retrieves the layout information for each field using uses a combination of the tag and the field name. If this combination doesn't uniquely identify the field (as in your example, where multiple untagged structs share a field name), then this scheme won't work.
I tried to add some stamp as workaround. The stamps are generated for each new structure. This break even more test so I think I have missed some place that need to be updated.
I expect this test to pass since it is copy pasted from a previous valid test. The generated code trigger ocaml warning 11 and I think it should be related. I don't know how to fix if you give me pointer I can try.
I get:
I also tried to reproduce with union and got same warning.
So this seem to be same issue
I don't see test for anonymous enum and I think we can trigger this defect in some unusual compiler like chibicc. See on https://godbolt.org with:
Since gcc and clang, tcc emit an error this should be a faulty compiler. However for struct this pattern can be seen on skia https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/include/c/sk_types.h#L77-L89