`MethodTypeInferrer.Fix` has potential exposure to `null` compilation
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
After annotating `MethodTypeInferrer._compilation`, it became clear that one of the usage sites is not prepared to deal with `null`, which could lead to a `null` dereference.
In practice, I don't think this is reachable at the moment, because a `null` compilation is used when reducing extension methods and new extension members, and I don't think a function type could contribute to the inference in such a case. But we should confirm and strengthen this code.
```
bool fromFunctionType = false;
if (isFunctionType(best, out var functionType))
{
// Realize the type as TDelegate, or Expression if the type parameter
// is constrained to System.Linq.Expressions.Expression.
var resultType = functionType.GetInternalDelegateType();
if (hasExpressionTypeConstraint(typeParameter))
{
var expressionOfTType = compilation.GetWellKnownType(WellKnownType.System_Linq_Expressions_Expression_T);
resultType = expressionOfTType.Construct(resultType);
}
best = TypeWithAnnotations.Create(resultType, best.NullableAnnotation);
fromFunctionType = true;
}
```
Found in https://github.com/dotnet/roslyn/pull/80659
Contributor guide
Assessment
This issue has not been assessed yet.