-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not include function type conversions in user-defined conversions #56416
Conversation
@@ -642,6 +642,9 @@ private static bool IsEncompassingImplicitConversionKind(ConversionKind kind) | |||
|
|||
// Added for C# 7.1 | |||
case ConversionKind.DefaultLiteral: | |||
|
|||
// Added for C# 10. | |||
case ConversionKind.FunctionType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c9825eb
to
958c08f
Compare
…ups to Delegate, Expression, and base types
68be73b
to
f8c5df3
Compare
@@ -118,6 +119,13 @@ public Conversion ClassifyImplicitConversionFromExpression(BoundExpression sourc | |||
} | |||
} | |||
} | |||
else if (sourceExpression.GetFunctionType() is { }) | |||
{ | |||
if (IsValidFunctionTypeConversionTarget(destination, ref useSiteInfo)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added handling of conversions between function types.
} | ||
|
||
Debug.Assert(false); | ||
return Conversion.NoConversion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
Debug.Assert((object)source != null); | ||
Debug.Assert((object)destination != null); | ||
Debug.Assert(source is not FunctionTypeSymbol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
if (IsValidFunctionTypeConversionTarget(destination, ref useSiteInfo)) | ||
{ | ||
return Conversion.FunctionType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -258,8 +258,8 @@ bool populateDisposableConversionOrDisposeMethod(bool fromExpression, out Conver | |||
Conversion classifyConversion(bool fromExpression, TypeSymbol targetInterface, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo) | |||
{ | |||
return fromExpression ? | |||
originalBinder.Conversions.ClassifyImplicitConversionFromExpression(expressionOpt, targetInterface, ref useSiteInfo) : | |||
originalBinder.Conversions.ClassifyImplicitConversionFromType(declarationTypeOpt, targetInterface, ref useSiteInfo); | |||
originalBinder.Conversions.ClassifyImplicitConversionFromExpression(expressionOpt!, targetInterface, ref useSiteInfo) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with review pass (commit 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 6)
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
,Expression
or a base type) are not considered for user-defined conversions.Fixes #56407
Relates to test plan #52192