Implement generate method and constructor with top-level nullability tracking wrapper#36049
Conversation
7fba867 to
ec4e35f
Compare
src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
should CreateTypeParameterSymbol just return a symbol that has the nullability?
...table/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/InternalUtilities/InternalExtensions.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
so, this def doesn't seem like it would work for anything but types. This may likely matter. for example, with implement-interface, we may compare a method like Foo(string?) to Foo(string) and want them to be equal in terms of how interface-implementation sees things.
There was a problem hiding this comment.
so, we're following compiler semantics here around equals. namely that it doesn't consider nullability?
There was a problem hiding this comment.
Well, right now this Equals implements the same semantics that the compiler currently implements in that it actually does look at nullability. Once we do the pass to use explicit comparers everywhere then this will be somewhat moot.
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NamedTypeSymbolWithNullableAnnotation.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NullableExtensions.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NamedTypeSymbolWithNullableAnnotation.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Utilities/NullableHelpers/TypeSymbolWithNullableAnnotation.cs
Outdated
Show resolved
Hide resolved
|
Overall 👍 on the effort. If anything, this PR just makes me think the end outcome needs to be "the compiler absorbs this" :). Right now, it feels like you'll have to basically audit/update nearly every use of compiler APIs, effectively causing a ton of rewriting. |
ec4e35f to
ce49932
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5bed8ea to
147946c
Compare
src/Workspaces/Core/Portable/Utilities/NullableHelpers/TypeSymbolWithNullableAnnotation.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NullableExtensions.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.SubstituteTypesVisitor.cs
Outdated
Show resolved
Hide resolved
ryzngard
left a comment
There was a problem hiding this comment.
Overall everything looks good to me, with the expected caveats of some things are hacky and make us all sad. Would like to see WithoutNullability rename happen, but I won't block on it.
Currently, the APIs for nullable reference types take a model that instead of the top level nullability of a named type being on the INamedTypeSymbol, it's carried along as a separate piece of information. This causes a lot of churn for code that is used to passing along ITypeSymbols today; one way to ease this is simply create a set of wrapper types which carry it along for us but still implement ITypeSymbol.
This enables basic support for applying top-level nullability to parameters and the return types when generating methods. Fixes dotnet#30319
This catches places we're calling Construct() or ClassifyConversion().
This makes the extension method work again. The workaround is tracked by dotnet#36093.
147946c to
68159bd
Compare
This is an implementation of generate method with nullability, which tries to use an experimental approach of creating our own implementation of ITypeSymbol that carries along top-level nullability. This means we can avoid having to change all our internal helpers away from passing around ITypeSymbol and incrementally update the support for the IDE.
Commit-at-a-time review suggested, since that'll split apart the wrappers themselves along with the actual "work" needed to fix the feature.