Refactor dereference operations into tagged unions #1603
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's just like rust enums no wayyyy
This PR tackles mainly nullability by refactoring the existing Dereference operation to be safer with the help of the type system.
The previous implementation used a struct called
Operation
, which held an enum value for what kind of operation the struct described as well as metadata about the operation. This resulted in a struct where pretty much every additional metadata was optional and had to be asserted at the time of checkingKind
, which wasn't very elegant.I refactored dereference operations by binding the metadata into types with one shared superclass called
Operation
.The subclasses are there to describe all kinds of different metadata that they need. To get the metadata, you can use type patterns to extract the data. This completely eliminates the need to assert no nullability with
!
, making the code much clearer and more elegant.Since
Operation
had to inherit from other things now, I had to turn it into a class. This has zero impact on performance since all operations were located on the heap anyways.Additionally I cleaned up some of the code involving dereferences. One less area with warnings.