Repository navigation
Analyzer suppression test fix - #2584
Conversation
If we think that the warning is valid and linker doesn't produce it then it's a bug in the linker. Somebody needs to investigate why the linker doesn't warn in this case. |
|
The reason the linker doesn't warn seems to be because we have |
|
|
|
This test is failing because it doesn't expect RUC from Expression.Call(). In runtime Expression.Call() is annotated with RUC (https://github.com/dotnet/runtime/blob/895c99cc502913fd7393b95af7cae5b9e6fbdea3/src/libraries/System.Linq.Expressions/ref/System.Linq.Expressions.cs#L439). Linker has intrinsics for handling it and that's why it doesn't warn. What I think the fix should be:
|
|
I was looking that currently the analyzer does the same with calls to |
| var expressionCallType = compilation.GetTypeByMetadataName ("System.Linq.Expressions.Expression"); | ||
| if (expressionCallType != null) { | ||
| incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> () | ||
| .Where (m => m.Parameters.Length == 4 && m.Parameters[0] is IParameterSymbol parameterSymbol |
There was a problem hiding this comment.
The list of incompatible member purposes is to say "RequiresUnreferencedCodeAnalyzer please don't analyze this call" then the dataflow will handle the intrinsic and decide if it needs to warn or not. You are restricting the number of parameters and type of the parameter, which means that RequiresUnreferencedCodeAnalyzer will only bypass that case and for everything else will warn. Im afraid that dataflow will do something similar and we end up generating two warnings, I think what we want is:
- incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> ()
- .Where (m => m.Parameters.Length == 4 && m.Parameters[0] is IParameterSymbol parameterSymbol
- && parameterSymbol.Type?.ContainingNamespace?.Name == "System" && parameterSymbol.Type?.Name == "Type"));
+ incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> ());There was a problem hiding this comment.
I think #2578 will require a more general solution but I am fine with this change doing the minimum necessary to get the suppression tests working.
| var expressionCallType = compilation.GetTypeByMetadataName ("System.Linq.Expressions.Expression"); | ||
| if (expressionCallType != null) { | ||
| incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> () | ||
| .Where (m => m.Parameters.Length == 4 && m.Parameters[0] is IParameterSymbol parameterSymbol |
There was a problem hiding this comment.
I think #2578 will require a more general solution but I am fine with this change doing the minimum necessary to get the suppression tests working.
* warning suppression test fix * FB * fb - missed a duplicated check Commit migrated from dotnet/linker@b96c89a
Fix for #2579, Roslyn handles
UnconditionalSuppressMessageon its own and we are not planning to add any special handling. The PR addresses the following 3 exceptions from the test bed.SuppressWarningsInMembersAndTypesUsingTarget: This test case uses Expression.Call which has a RUC but is treated as an intrinsic by the trimmer. Ensured that the analyzer handles this method correctlySuppressWarningsInCompilerGeneratedCode: Analyzer and Linker differ in the warning code generated. Filed [feature/damAnalyzer] Warning code differ between the linker and analyzer #2583 (and [DAM analyzer] don't produce dataflow warnings for compiler-generated code #2587 also has relevant information) for thisSuppressWarningsViaXml: As [DAM analyzer] Add support for attribute warning suppressions #2579 (comment) discussion notes, we plan on not supporting this in the analyzer, at least for the time being. The test does not run in the analyzer.