3 ms·
Oh that's probably doable. Introducing something like this is a bit orthogonal to the point above, but yes. It's not straightforward but probably something tha
by aatd86 1y ago
Oh that's probably doable. Introducing something like this is a bit orthogonal to the point above, but yes.
It's not straightforward but probably something that will be considered at some point I reckon when thinking about making union interfaces first class.
That will require to track a not nil typestate/predicate in the backend, something like that I guess.
- rowanseymour 1y agoHaving pondered on a bit more.. I think it's the struct that would declare that it's not usable as nil, and that in turn would tell the runtime not to box it if it's nil. That would also help the compiler (and copilot etc) spot calls on nil pointers which will panic.
- aatd86 1y agoBut that information disappears when you assign to an interface variable/container that is nillable. It requires an assertion to recover the info about the value inside the interface being not nil. basically `if v.(nil){...} creates two branches. In one we know v is not nil (outside the if block) and it can therefore be assigned to non nillable variables so to speak...