Skip to content

Commit

Permalink
Merge pull request dotnet#54142 from AlekseyTs/StaticAbstractMembersI…
Browse files Browse the repository at this point in the history
…nInterfaces_32

Merge 'features/StaticAbstractMembersInInterfaces' into 'main'
  • Loading branch information
jaredpar authored Jun 16, 2021
2 parents 4fb8c42 + 07e319e commit 6920e1e
Show file tree
Hide file tree
Showing 197 changed files with 39,299 additions and 1,865 deletions.
14 changes: 14 additions & 0 deletions docs/features/StaticAbstractMembersInInterfaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Static Abstract Members In Interfaces
=====================================

An interface is allowed to specify abstract static members that implementing classes and structs are then
required to provide an explicit or implicit implementation of. The members can be accessed off of type
parameters that are constrained by the interface.

Proposal:
- https://github.com/dotnet/csharplang/issues/4436
- https://github.com/dotnet/csharplang/blob/main/proposals/static-abstracts-in-interfaces.md

Feature branch: https://github.com/dotnet/roslyn/tree/features/StaticAbstractMembersInInterfaces

Test plan: https://github.com/dotnet/roslyn/issues/52221
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ private bool CheckPropertyValueKind(SyntaxNode node, BoundExpression expr, BindV
return false;
}

CheckRuntimeSupportForSymbolAccess(node, receiver, setMethod, diagnostics);
CheckReceiverAndRuntimeSupportForSymbolAccess(node, receiver, setMethod, diagnostics);
}
}

Expand Down Expand Up @@ -1177,7 +1177,7 @@ private bool CheckPropertyValueKind(SyntaxNode node, BoundExpression expr, BindV
return false;
}

CheckRuntimeSupportForSymbolAccess(node, receiver, getMethod, diagnostics);
CheckReceiverAndRuntimeSupportForSymbolAccess(node, receiver, getMethod, diagnostics);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,11 @@ private static string GetMethodName(BaseMethodDeclarationSyntax baseMethodDeclar
case SyntaxKind.DestructorDeclaration:
return WellKnownMemberNames.DestructorName;
case SyntaxKind.OperatorDeclaration:
return OperatorFacts.OperatorNameFromDeclaration((OperatorDeclarationSyntax)baseMethodDeclarationSyntax);
var operatorDeclaration = (OperatorDeclarationSyntax)baseMethodDeclarationSyntax;
return ExplicitInterfaceHelpers.GetMemberName(outerBinder, operatorDeclaration.ExplicitInterfaceSpecifier, OperatorFacts.OperatorNameFromDeclaration(operatorDeclaration));
case SyntaxKind.ConversionOperatorDeclaration:
return ((ConversionOperatorDeclarationSyntax)baseMethodDeclarationSyntax).ImplicitOrExplicitKeyword.Kind() == SyntaxKind.ImplicitKeyword
? WellKnownMemberNames.ImplicitConversionName
: WellKnownMemberNames.ExplicitConversionName;
var conversionDeclaration = (ConversionOperatorDeclarationSyntax)baseMethodDeclarationSyntax;
return ExplicitInterfaceHelpers.GetMemberName(outerBinder, conversionDeclaration.ExplicitInterfaceSpecifier, OperatorFacts.OperatorNameFromDeclaration(conversionDeclaration));
case SyntaxKind.MethodDeclaration:
MethodDeclarationSyntax methodDeclSyntax = (MethodDeclarationSyntax)baseMethodDeclarationSyntax;
return ExplicitInterfaceHelpers.GetMemberName(outerBinder, methodDeclSyntax.ExplicitInterfaceSpecifier, methodDeclSyntax.Identifier.ValueText);
Expand Down
23 changes: 22 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected BoundExpression CreateConversion(

// Obsolete diagnostics for method group are reported as part of creating the method group conversion.
ReportDiagnosticsIfObsolete(diagnostics, conversion, syntax, hasBaseReceiver: false);
CheckConstraintLanguageVersionAndRuntimeSupportForConversion(syntax, conversion, diagnostics);

if (conversion.IsAnonymousFunction && source.Kind == BoundKind.UnboundLambda)
{
Expand Down Expand Up @@ -214,6 +215,25 @@ protected BoundExpression CreateConversion(
{ WasCompilerGenerated = wasCompilerGenerated };
}

internal void CheckConstraintLanguageVersionAndRuntimeSupportForConversion(SyntaxNodeOrToken syntax, Conversion conversion, BindingDiagnosticBag diagnostics)
{
if (conversion.IsUserDefined && conversion.Method is MethodSymbol method && method.IsStatic && method.IsAbstract)
{
Debug.Assert(conversion.ConstrainedToTypeOpt is TypeParameterSymbol);

if (Compilation.SourceModule != method.ContainingModule)
{
Debug.Assert(syntax.SyntaxTree is object);
CheckFeatureAvailability(syntax.SyntaxTree, MessageID.IDS_FeatureStaticAbstractMembersInInterfaces, diagnostics, syntax.GetLocation()!);

if (!Compilation.Assembly.RuntimeSupportsStaticAbstractMembersInInterfaces)
{
Error(diagnostics, ErrorCode.ERR_RuntimeDoesNotSupportStaticAbstractMembersInInterfaces, syntax);
}
}
}
}

private BoundExpression ConvertObjectCreationExpression(SyntaxNode syntax, BoundUnconvertedObjectCreationExpression node, bool isCast, TypeSymbol destination, BindingDiagnosticBag diagnostics)
{
var arguments = AnalyzedArguments.GetInstance(node.Arguments, node.ArgumentRefKindsOpt, node.ArgumentNamesOpt);
Expand Down Expand Up @@ -346,6 +366,7 @@ private BoundExpression CreateUserDefinedConversion(
bool hasErrors)
{
Debug.Assert(conversionGroup != null);
Debug.Assert(conversion.IsUserDefined);

if (!conversion.IsValid)
{
Expand Down Expand Up @@ -788,7 +809,7 @@ private bool MemberGroupFinalValidation(BoundExpression? receiverOpt, MethodSymb
{
if (!IsBadBaseAccess(node, receiverOpt, methodSymbol, diagnostics))
{
CheckRuntimeSupportForSymbolAccess(node, receiverOpt, methodSymbol, diagnostics);
CheckReceiverAndRuntimeSupportForSymbolAccess(node, receiverOpt, methodSymbol, diagnostics);
}

if (MemberGroupFinalValidationAccessibilityChecks(receiverOpt, methodSymbol, node, diagnostics, invokedAsExtensionMethod))
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ private static ImmutableArray<Symbol> PerformCrefOverloadResolution(ArrayBuilder
name: null,
refKind: RefKind.None,
isInitOnly: false,
isStatic: false,
returnType: default,
refCustomModifiers: ImmutableArray<CustomModifier>.Empty,
explicitInterfaceImplementations: ImmutableArray<MethodSymbol>.Empty);
Expand Down
Loading

0 comments on commit 6920e1e

Please sign in to comment.