Fix null reference exception with convert tuple with inaccessible System.HashCode
ConvertTupleToStruct invokes our existing services for generating GetHashCode methods; that service checks whether System.HashCode is available, and if so uses it rather than implementing the hash code combining manually. The code to generate GetHashCode correctly not just grabs the type but also tries to check whether type is accessible to the struct being generated. It's possible for System.HashCode to be internal if some library you're referencing has embedded it's own copy; in this case we were trying to check if the System.HashCode was accessible to the code generation symbol; if the System.HashCode was internal it then checks the assembly symbols for InternalsVisibleTo, but since the code generation symbol never had a ContainingAssembly this would crash with a null reference. Much of this code is null annotated, but unfortunately we have yet to annotate ContainingAssembly, so the line of code that let a null get into the system was here: https://github.com/dotnet/roslyn/blob/884fdff6f8a87faa7f6e65d762bd6d7b2025da74/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ISymbolExtensions_Accessibility.cs#L230 My fix is to create the code generation INamedTypeSymbol with a containing assembly, which allows the rest of the checks to work correctly.
Showing
想要评论请 注册 或 登录