-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable nullable (and resolve most nullable warnings) #119
Open
Hamunii
wants to merge
25
commits into
IAmBatby:experimental
Choose a base branch
from
Hamunii:enable-nullable
base: experimental
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Enables the Nullable feature of C# in csproj to help better deal with null values.
Basically, this will make you specify if your variable types are nullable or not.
For example, you'll need to write
string? something;
instead ofstring something;
if thesomething
variable might be null, so the IDE knows to warn you when you try to access the variable and it isn't sure it's not null (This will help catch Null Reference Exceptions much easier). See https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-value-typesYou can use
string something = null!;
instead if you know this won't be null when it matters or whatever. See https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-forgivingI also tried to resolve most nullable warnings, by quickly looking how each variable with a nullability warning was used, and marked them as nullable if there was code that checked if they were null in other places than just some init methods. A lot of what I did might not be perfect, but it's a lot better than nothing.
There are still a few nullable warnings that I didn't analyze enough (of the ones I did go through), since I marked a thing as nullable because from the code it seemed like there were a lot of null checks for it, but then it's used in some patches without checking for null. So these need to be reviewed a little more closely, but I'm done for today with this.
Also related:
For when(/if) you make more
TryGet
methods that give back a nullable variable type that is known to be null when return value is false and not null when return value is true, there is an attribute for marking that, e.g.[NotNullWhen(returnValue: true)] out ExtendedDungeonFlow? returnExtendedDungeonFlow
: https://stackoverflow.com/a/57627724