Do not include function type conversions in user-defined conversions#56416
Do not include function type conversions in user-defined conversions#56416cston merged 6 commits intodotnet:mainfrom
Conversation
| case ConversionKind.DefaultLiteral: | ||
|
|
||
| // Added for C# 10. | ||
| case ConversionKind.FunctionType: |
c9825eb to
958c08f
Compare
…ups to Delegate, Expression, and base types
68be73b to
f8c5df3
Compare
| } | ||
| else if (sourceExpression.GetFunctionType() is { }) | ||
| { | ||
| if (IsValidFunctionTypeConversionTarget(destination, ref useSiteInfo)) |
There was a problem hiding this comment.
The only code paths that should have to handle conversions between two function types are BestTypeInferrer and MethodTypeInferrer in cases where "bounds" are merged. Those code paths use ClassifyImplicitConversionFromTypeOrImplicitFunctionTypeConversion().
There was a problem hiding this comment.
Added handling of conversions between function types.
| } | ||
|
|
||
| Debug.Assert(false); | ||
| return Conversion.NoConversion; |
There was a problem hiding this comment.
The only callers of this method are BestTypeInferrer and MethodTypeInferrer in cases where "bounds" are merged. In those cases, there are either two function types or two types that are not function types, so conversions from function type to non-function type do not need to be considered.
| return conversion; | ||
| } | ||
|
|
||
| private Conversion ClassifyStandardImplicitConversionInternal(TypeSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo) |
| { | ||
| Debug.Assert((object)source != null); | ||
| Debug.Assert((object)destination != null); | ||
| Debug.Assert(source is not FunctionTypeSymbol); |
| { | ||
| if (IsValidFunctionTypeConversionTarget(destination, ref useSiteInfo)) | ||
| { | ||
| return Conversion.FunctionType; |
| return fromExpression ? | ||
| originalBinder.Conversions.ClassifyImplicitConversionFromExpression(expressionOpt, targetInterface, ref useSiteInfo) : | ||
| originalBinder.Conversions.ClassifyImplicitConversionFromType(declarationTypeOpt, targetInterface, ref useSiteInfo); | ||
| originalBinder.Conversions.ClassifyImplicitConversionFromExpression(expressionOpt!, targetInterface, ref useSiteInfo) : |
|
Done with review pass (commit 3) |
Removes "function type conversions" from the set of "standard conversions" so that function type conversions (from the inferred type of a lambda expression or method group to
Delegate,Expressionor a base type) are not considered for user-defined conversions.Fixes #56407
Relates to test plan #52192