-
Notifications
You must be signed in to change notification settings - Fork 8
Null annotations and in string args
#142
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
Changes from all commits
b2f0dd6
5b35862
246b720
5f29271
9432268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,9 +103,12 @@ int LoadModule(ILua lua) | |
|
|
||
| foreach (Type t in module_types) | ||
| { | ||
| IModule current_module = (IModule)Activator.CreateInstance(t); | ||
| modules.Add(current_module); | ||
| gc_handles.Add(GCHandle.Alloc(current_module)); | ||
| IModule? current_module = Activator.CreateInstance(t) as IModule; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it's nullable?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CreateInstance has null annotation on return type: https://learn.microsoft.com/en-us/dotnet/api/system.activator.createinstance?view=net-7.0#system-activator-createinstance(system-type)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why? We literally check if it is null in a next line. Let it be this way until Microsoft provide non-nulable guaranties for |
||
| if (current_module is not null) | ||
| { | ||
| modules.Add(current_module); | ||
| gc_handles.Add(GCHandle.Alloc(current_module)); | ||
| } | ||
| } | ||
|
|
||
| if (modules.Count == 0) | ||
|
|
@@ -150,7 +153,7 @@ WeakReference<GmodNetModuleAssemblyLoadContext> UnloadHelper(string module_name) | |
| { | ||
| foreach (GCHandle h in module_contexts[module_name].Item2) | ||
| { | ||
| ((IModule)h.Target).Unload(lua); | ||
| (h.Target as IModule)?.Unload(lua); | ||
| h.Free(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but C# null checker is not satisfied otherwise.