The setTypeId rule
One rule in Paternitas is yours to keep.
The compiler cannot check it.
Call it after you create the struct
Call it even when every field has its default value.
- A new struct has no type id.
- Paternitas does not set the type id by itself.
NAQ: Why can Paternitas not set the type id by itself?
The TypedNode is one type, shared by every struct that uses it.
Its default value is the same for a Message and for a Job.
So the default cannot know which struct it is in. setTypeId can.
Memory from allocator.create is undefined.
- Set up the struct first.
- Then call
setTypeId.
Call it again after a whole-struct write
A whole-struct write replaces the type id too.
- an assignment,
message = .{ ... }; - a reset of the whole struct
- a clear of the whole struct
- a zero-fill of the whole struct
Call setTypeId right after each one:
Writing one field is fine.
message.text = "again";changes one field.- The type id stays there.
One struct, one list does the reset, and checks the struct comes back.
Forgot it?
Nothing breaks at once. The checks just never match.
| call | what you get |
|---|---|
parentFromNode(node) |
null |
mustParentFromNode(node) |
a panic: found <no type> |
is(node) |
false |
parentFromAnchor(a) |
null |
anchor.info() |
null |
The panic looks like this:
When you see <no type>, look for the place that created the struct, or wrote all of it.
fromAny is different.
- When runtime safety is on, a missing call panics.
- In ReleaseFast and ReleaseSmall, nothing catches it.