Skip to content
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

Implement improved overload candidates, aka "Bestest Betterness". #24756

Merged
merged 5 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
return ToBadExpression(expr, resultKind);
}

internal static bool IsTypeOrValueExpression(BoundExpression expression)
{
switch (expression?.Kind)
{
case BoundKind.TypeOrValueExpression:
case BoundKind.QueryClause when ((BoundQueryClause)expression).Value.Kind == BoundKind.TypeOrValueExpression:
return true;
default:
return false;
}
}

/// <summary>
/// The purpose of this method is to determine if the expression satisfies desired capabilities.
/// If it is not then this code gives an appropriate error message.
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ internal bool BindingTopLevelScriptCode
get
{
var containingMember = this.ContainingMemberOrLambda;
switch (containingMember.Kind)
switch (containingMember?.Kind)
Copy link
Member

@jcouv jcouv Feb 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand what prompted this change. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now used in error scenarios where containingMember can be null.


In reply to: 167699262 [](ancestors = 167699262)

{
case SymbolKind.Method:
// global statements
Expand Down
21 changes: 12 additions & 9 deletions src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ private static bool IsMethodGroupWithTypeOrValueReceiver(BoundNode node)
return false;
}

BoundNode receiverOpt = ((BoundMethodGroup)node).ReceiverOpt;
return receiverOpt != null && receiverOpt.Kind == BoundKind.TypeOrValueExpression;
return Binder.IsTypeOrValueExpression(((BoundMethodGroup)node).ReceiverOpt);
}

private BoundMethodGroup FixMethodGroupWithTypeOrValue(BoundMethodGroup group, Conversion conversion, DiagnosticBag diagnostics)
Expand Down Expand Up @@ -572,7 +571,7 @@ private bool MemberGroupFinalValidationAccessibilityChecks(BoundExpression recei
//note that the same assert does not hold for all properties. Some properties and (all indexers) are not referenceable by name, yet
//their binding brings them through here, perhaps needlessly.

if (receiverOpt != null && receiverOpt.Kind == BoundKind.TypeOrValueExpression)
if (IsTypeOrValueExpression(receiverOpt))
{
// TypeOrValue expression isn't replaced only if the invocation is late bound, in which case it can't be extension method.
// None of the checks below apply if the receiver can't be classified as a type or value.
Expand Down Expand Up @@ -678,7 +677,7 @@ private static bool IsMemberAccessedThroughVariableOrValue(BoundExpression recei
return !IsMemberAccessedThroughType(receiverOpt);
}

private static bool IsMemberAccessedThroughType(BoundExpression receiverOpt)
internal static bool IsMemberAccessedThroughType(BoundExpression receiverOpt)
{
if (receiverOpt == null)
{
Expand All @@ -696,7 +695,7 @@ private static bool IsMemberAccessedThroughType(BoundExpression receiverOpt)
/// <summary>
/// Was the receiver expression compiler-generated?
/// </summary>
private static bool WasImplicitReceiver(BoundExpression receiverOpt)
internal static bool WasImplicitReceiver(BoundExpression receiverOpt)
{
if (receiverOpt == null) return true;
if (!receiverOpt.WasCompilerGenerated) return false;
Expand Down Expand Up @@ -808,8 +807,8 @@ private bool MethodGroupConversionHasErrors(

MethodSymbol selectedMethod = conversion.Method;

if (MemberGroupFinalValidation(receiverOpt, selectedMethod, syntax, diagnostics, isExtensionMethod) ||
!MethodGroupIsCompatibleWithDelegate(receiverOpt, isExtensionMethod, selectedMethod, delegateType, syntax.Location, diagnostics))
if (!MethodGroupIsCompatibleWithDelegate(receiverOpt, isExtensionMethod, selectedMethod, delegateType, syntax.Location, diagnostics) ||
MemberGroupFinalValidation(receiverOpt, selectedMethod, syntax, diagnostics, isExtensionMethod))
{
return true;
}
Expand Down Expand Up @@ -864,8 +863,12 @@ private bool MethodGroupConversionDoesNotExistOrHasErrors(
diagnostics.Add(delegateMismatchLocation, useSiteDiagnostics);
if (!conversion.Exists)
{
// No overload for '{0}' matches delegate '{1}'
diagnostics.Add(ErrorCode.ERR_MethDelegateMismatch, delegateMismatchLocation, boundMethodGroup.Name, delegateType);
if (!Conversions.ReportDelegateMethodGroupDiagnostics(this, boundMethodGroup, delegateType, diagnostics))
{
// No overload for '{0}' matches delegate '{1}'
diagnostics.Add(ErrorCode.ERR_MethDelegateMismatch, delegateMismatchLocation, boundMethodGroup.Name, delegateType);
}

return true;
}
else
Expand Down
Loading