dotnet / dotnet/linker

Analyzer processes expression tree construction data flow differently from linker

Open
#3,172 1 comment 0 reactions 0 assignees View on GitHub
area-Analyzers
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

For example:

```C#
public static void MethodWithSingleAnnotatedParameter (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
{ }

static void LdToken ()
{
// Linker produces IL2111
// Analyzer produces IL2067
Expression> _ = (Type t) => MethodWithSingleAnnotatedParameter (t);

// Linker produces IL2111
// Analyzer doesn't warn
Expression _ = () => MethodWithSingleAnnotatedParameter (typeof(string));
}
```

The difference is because linker sees `ldtoken` and not an actual call and doesn't perform true data flow, but analyzer sees this as a normal statement and processes it through data flow.
The linker behavior is correct here, under the hood this creates expression tree with MethodInfo which is publicly accessible. And anybody with the expression tree can invoke the MethodInfo with any input. So this needs to warn always, regardless of data flow.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.