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

Merge 'features/StaticAbstractMembersInInterfaces' into 'main' #54142

Merged
merged 62 commits into from
Jun 16, 2021

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

msftbot[bot] and others added 30 commits March 27, 2021 16:30
Merge 'main' into 'features/StaticAbstractMembersInInterfaces'
…events in interfaces. (dotnet#52228)

Spec: https://github.com/dotnet/csharplang/blob/9a0dddbf0643993db0da8f48436f2aac60bc20b1/proposals/statics-in-interfaces.md

Related to dotnet#52202.

Relevant quotes from the spec:

#### Abstract virtual members
Static interface members other than fields are allowed to also have the `abstract` modifier. Abstract static members are not allowed to have a body (or in the case of properties, the accessors are not allowed to have a body). 

``` c#
interface I<T> where T : I<T>
{
    static abstract void M();
    static abstract T P { get; set; }
    static abstract event Action E;
    static abstract T operator +(T l, T r);
}
```

#### Explicitly non-virtual static members
For symmetry with non-virtual instance members, static members should be allowed an optional `sealed` modifier, even though they are non-virtual by default:

``` c#
interface I0
{
    static sealed void M() => Console.WriteLine("Default behavior");
    
    static sealed int f = 0;
    
    static sealed int P1 { get; set; }
    static sealed int P2 { get => f; set => f = value; }
    
    static sealed event Action E1;
    static sealed event Action E2 { add => E1 += value; remove => E1 -= value; }
    
    static sealed I0 operator +(I0 l, I0 r) => l;
}
```
…feature. (dotnet#52366)

Spec: https://github.com/dotnet/csharplang/blob/3e6e0d77504b6d05eaec4232303d58b1fd806b51/proposals/statics-in-interfaces.md

- Added tests to verify metadata produced for abstract static memebers in interfaces.
- Added a temporary stub for the runtime support check.
- Adjusted variance safety checks for signatures of abstract static members.
- Adjusted generic constraints checks to disallow interfaces as type arguments for type parameters that are constrained to an interface with static abstract members.
- Relaxed signature requirements for abstract user-defined operators.

Relevant quotes from the spec:

## Operator restrictions

Today all unary and binary operator declarations have some requirement involving at least one of their operands to be of type `T` or `T?`, where `T` is the instance type of the enclosing type.

These requirements need to be relaxed so that a restricted operand is allowed to be of a type parameter that is constrained to `T`.

## Interface constraints with static abstract members

Today, when an interface `I` is used as a generic constraint, any type `T` with an implicit reference or boxing conversion to `I` is considered to satisfy that constraint.

When `I` has static abstract members this needs to be further restricted so that `T` cannot itself be an interface.

## Variance safety
https://github.com/dotnet/csharplang/blob/main/spec/interfaces.md#variance-safety

Variance safety rules should apply to signatures of static abstract members. The addition proposed in
https://github.com/dotnet/csharplang/blob/main/proposals/variance-safety-for-static-interface-members.md#variance-safety
should be adjusted from

*These restrictions do not apply to occurrences of types within declarations of static members.*

to

*These restrictions do not apply to occurrences of types within declarations of **non-virtual, non-abstract** static members.*

* Adjust an error message
…nInterfaces_05

Merge 'dotnet/main' into `StaticAbstractMembersInInterfaces`
…in classes and structures (dotnet#52969)

In metadata an implementation should be a static, not newslot, not final, not virtual, not abstract method. Type should have a MethodImpl entry pointing to the ”body” method with a MethodDef index. The “body” must be a method declared within the type. There is no concept of an implicit interface implementation for static methods in metadata. I.e., if there is no corresponding MethodImpl entry, the method isn’t an implementation from runtime point of view.

Language supports both implicit and explicit interface implementation.

Relevant ECMA-335 changes PR - dotnet/runtime#49558
…ourceUserDefinedOperatorSymbolBase to prepare for explicit implementations of operators (dotnet#53058)

Shared code is pulled from derived types to the new base. This is just a refactoring, no behavior changes intended.

However, there is a change in behavior that addresses dotnet#53069.
…in operators. (dotnet#53142)

Also adding a bunch of parsing tests for scenarios without modifiers.
…s in classes and structures (dotnet#53130)

This includes support for implicit and explicit implementations.
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Need a sign-off on a merge PR.

@Cosifne
Copy link
Member

Cosifne commented Jun 16, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jaredpar jaredpar merged commit 6920e1e into dotnet:main Jun 16, 2021
@ghost ghost added this to the Next milestone Jun 16, 2021
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants