-
Notifications
You must be signed in to change notification settings - Fork 127
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
Fix null refs in byte array COM interop #2688
Conversation
There may still be holes to be addressed with Roslyn types not being nullable.
@@ -88,11 +88,11 @@ static bool IsComInterop (ISymbol symbol) | |||
if (typeSymbol == null) | |||
return false; | |||
|
|||
if (typeSymbol.ContainingNamespace.Name == "System" && typeSymbol.Name == "Array") { | |||
if (typeSymbol.ContainingNamespace?.Name == "System" && typeSymbol.Name == "Array") { |
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.
Don't we have enabled nullable to catch such errors?
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.
See #2687.
The issues were fixed by #2692, this now just adds tests. |
For my education, how does adding new tests fix the original issue? Where is the source code change that fixed #2686? |
Roslyn API doesn't use nullable types and will return null on properties and fields that aren't annotated with the
?
. The linker assumes that fields will not be null, and those issues tend to appear most frequently with COM interop when a type doesn't have a namespace.This fixes the null reference in a minimal repro, but there are likely more holes to address #2687.
This should fix #2686.
I wasn't sure where the test case best fits in, so it's in a separate file in the
Interop
test cases folder. Let me know if there's a better place for it.