Freedom-of-Form-Foundation / anatomy3d

A CAD tool for humanoid anatomy alterations. See the anatomy3d-blender repository for more recent work.
https://freedomofform.org/1856/3d-anatomy-project-scope-phase-1-focus-on-a-limb-joint/
GNU General Public License v2.0
7 stars 5 forks source link

Enable nullability annotation checking and enforcement #74

Open AdamNorberg opened 2 years ago

AdamNorberg commented 2 years ago

C# 8.0 adds new syntax for tracking nullability of fields: by default, fields cannot be null, but if the type is suffixed with ?, then it can be nullable. (Note that this is identical to the syntax that produces a nullable value type.) This lets the compiler force us to not make various null pointer errors; in exchange, we have to do some mass refactoring.

At the start, we'll enable nullability enforcement project-wide, but then mark (almost?) every file as #pragma nullable disable, which is a TODO mark of a sort until we migrate those files. The goal is to get every file nullable-correct with no remaining #pragma nullable disable directives.

To convert from a nullable type to a non-nullable type in code - that is, we genuinely have a value that might be null, and we need to send it to somewhere we can't have a null - we should add the null-check we should have had in the first place (and nullability annotations just surfaced the necessity of). If we are very certain a field cannot be null at a certain point despite its nullable type and the compiler not identifying the context as guaranteed nonnull, there is a "nonnull asserting" syntax (it uses exclamation marks in weird spots), but I want at least a comment describing why we are confident in the nonnullability assertion everywhere we use one.

https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references has more information.

AdamNorberg commented 2 years ago

Blocked by #13.