I recently ran into a collision between using’d struct fields. There doesn’t really seem to be any mechanism to resolve that, besides renaming the fields or using #subtype instead of using.
I think it would be useful to be able to exclude specific fields on a struct from getting pulled in when the struct gets using’d, as these conflicts often happen with fields that I don’t even really want to pull in anyway. The two scenarios where I can see this being most useful are:
- Having a struct that’s
usingmultiple component structs, that holdusingpointers back to some base struct. - Having a struct that’s
usingmultiple structs with vtable fields (which preferably would just be named ‘vtable’)
Syntax wise, I could imagine it being something like a #hidden directive before a a struct field.
Example: (scenario 1)
Player:: struct {
using entity: Base_Entity,
using component_a: Component_A,
using component_b: Component_B,
some_entity_field: u8,
// No collision between component_a.entity and component_b.entity
// Those fields must be accessed explicitly
}
Component_A :: struct {
#hidden using entity: ^Base_Entity,
some_component_field: u8,
}
Component_B :: struct {
#hidden using entity: ^Base_Entity,
some_other_component_field: u8,
}
This seems like something that might’ve already been considered, though I couldn’t find any earlier discussion about it. Curious what people think.
(I had also made a Github Discussion about this topic here.)