Add RequiresAssemblyFiles CodeFix#2015
Conversation
Add tests Fix dotnet#2005 Add other fixes that exist in RequiresUnreferencedCode but werent on RequiresAssemblyFiles
| ImmutableArray<ISymbol> dangerousPatterns) | ||
| { | ||
| // Find containing symbol | ||
| ISymbol? containingSymbol = null; |
There was a problem hiding this comment.
Isn't this FindAttributableParent?
There was a problem hiding this comment.
I don't think they are the same FindAttributableParent search for a Method/Property/Event/Field to put the attribute on, this function only looks for local functions and lambdas to warn and otherwise falls back to operationContext.ContainingSymbol
There was a problem hiding this comment.
Lambdas can't have attributes so I'm not clear on what this is supposed to be doing.
| var fieldAccess = (IFieldReferenceOperation) operationContext.Operation; | ||
| if (fieldAccess.Field.ContainingType is INamedTypeSymbol { StaticConstructors: var ctors } && | ||
| !SymbolEqualityComparer.Default.Equals (operationContext.ContainingSymbol.ContainingType, fieldAccess.Field.ContainingType)) { | ||
| CheckStaticConstructors (operationContext, ctors); |
There was a problem hiding this comment.
Why are we only checking for static constructors on field access?
| ImmutableArray<ISymbol> dangerousPatterns) | ||
| { | ||
| // Find containing symbol | ||
| ISymbol? containingSymbol = null; |
There was a problem hiding this comment.
Lambdas can't have attributes so I'm not clear on what this is supposed to be doing.
Add resources files PR comments
Use context.Options instead of context
| <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd"> | ||
| <file datatype="xml" source-language="en" target-language="cs" original="../Resources.resx"> | ||
| <body> | ||
| <trans-unit id="RequiresAssemblyFilesCodeFixTittle"> |
There was a problem hiding this comment.
We don't have localization so you can probably turn this off (I think there's a property in the analyzer project that's set that does this, something like <EnableXlfLocalization>false
| if (assemblyType != null) { | ||
| // properties | ||
| ImmutableArrayOperations.AddIfNotNull (dangerousPatternsBuilder, ImmutableArrayOperations.TryGetSingleSymbol<IPropertySymbol> (assemblyType.GetMembers ("Location"))); | ||
| protected override ImmutableArray<ISymbol> GetDangerousPatterns (Compilation compilation) |
There was a problem hiding this comment.
What does Pattern mean here? Members? Do we want to use the word Dangerous here?
There was a problem hiding this comment.
I could rename it to SpecialIncompatibleMembers
|
|
||
| protected abstract bool TryGetRequiresAttribute (ISymbol member, out AttributeData? requiresAttribute); | ||
|
|
||
| protected abstract bool ReportDangerousPatternDiagnostic (OperationAnalysisContext operationContext, ImmutableArray<ISymbol> dangerousPatterns, ISymbol member); |
There was a problem hiding this comment.
Some of these probably deserve doc comments. It's not clear to me what each method is supposed to do.
| <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd"> | ||
| <file datatype="xml" source-language="en" target-language="cs" original="../Resources.resx"> | ||
| <body> | ||
| <trans-unit id="RequiresAssemblyFilesCodeFixTittle"> |
| public partial class CSharpCodeFixVerifier<TAnalyzer, TCodeFix> | ||
| where TAnalyzer : DiagnosticAnalyzer, new() | ||
| where TCodeFix : CodeFixProvider, new() | ||
| where TCodeFix : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider, new() |
There was a problem hiding this comment.
By inserting a resource file in ILLink.CodeFixProvider I needed to add it as part of the using statements, creating ambiguity on what is a CodeFixProvider
|
If we remove the static constructor handling some of the tests in RequiresCapability will fail, but I just noticed that Marek disabled those test for being unreliable |
|
Ah, yes, we should re-enable those. What test fails though? Does the linker already check this functionality? |
|
I'm not sure which test was failing on CI, but if I remove the static constructor code it will fail on 3 of the RequiresCapability tests |
|
Awesome -- didn't realize this had already been implemented in the linker. Yeah, then we should keep this and add test coverage in the analyzer tests. I forgot the linker tests were disabled though, I'll look at that. |
Add document comments Re-enable RequiresCapability tests
agocke
left a comment
There was a problem hiding this comment.
LGTM!
Nice work, looks like a lot of cleaner sharing between the analyzers now
Add RequiresAssemblyFiles CodeFix Add tests Fix dotnet/linker#2005 Refactor analyzer code. Fixes dotnet/linker#1986 Add resources files to codefixer Commit migrated from dotnet/linker@2add126
Add RequiresAssemblyFiles CodeFix
Add tests
Fixes #2005
Fixes #1986
Add other fixes that exist in RequiresUnreferencedCode but weren't on RequiresAssemblyFiles