-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
Area-CompilersFeature - RefStructInterfaces`allows ref struct` (ref struct interfaces)`allows ref struct` (ref struct interfaces)
Milestone
Description
Championed proposal: dotnet/csharplang#7608
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-13.0/ref-struct-interfaces.md
Feature branch: https://github.com/dotnet/roslyn/tree/features/RefStructInterfaces
Compiler
- language version
- interface implementation
-
allows ref struct - generic type substitution
-
using,foreach, etc. with ref like type interface implementation
- target runtime support:
RuntimeFeature.ByRefLikeGenerics-
allows ref struct
-
-
ref structinterface implementation- implicit / explicit implementation
- default interface methods, properties, indexers, events, with
virtual/sealedmodifiers (see*_DefaultImplementation)
-
allows ref structconstraint (seeAllowsConstraint_*)- must be last
- duplicated constraint
- with
struct,class,new(),unmanaged,notnull,default, interface, class - on
partialtype / method - on override
- on implicit / explicit implementation
- constraint emitted to metadata
- constraint emitted to ref assembly (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, AllowsConstraint_01_SimpleTypeTypeParameter)
- calling instance members on value of type parameter with
allows ref struct- error calling
System.Objectmethods - error calling non-virtual default interface member (ERR_BadNonVirtualInterfaceMemberAccessOnAllowsRefLike error CS9246: A non-virtual instance interface member cannot be accessed on a type parameter that allows ref struct.)
- (open design question) warning calling virtual, non-abstract default interface member
- error calling
- conversions
- from:
ref struct - from: type parameter with
allows ref struct, with/withoutstructconstraint - from: implemented/unimplemented interface
- to:
System.Object - to:
ref struct - to: implemented/unimplemented interface
- to: same type parameter (IdentityConversion_01 .. IdentityConversion_04)
- to: type parameter with/without
allows ref struct, with/withoutstructconstraint - to: type parameter with
allows ref struct, with/withoutstructconstraint, with implemented interface constraint - to: type parameter with
allows ref struct, with/withoutstructconstraint, with unimplemented interface constraint - to: type parameter with/without
allows ref struct, with/withoutstructconstraint,where T : U/whereU : T`
- from:
-
isoperator:value is Type(seeIsOperator_*)- value:
ref structwith/without interface implementation - value: interface
- value: type parameter with/without
allows ref struct, with/withoutstructconstraint, with/without interface constraint - type:
ref struct - type: interface
- type: same type parameter
- type: type parameter with/without
allows ref struct, with/withoutstructconstraint, with/without interface constraint - type: type parameter with
classconstraint, with/without interface constraint (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, IsOperator_05, IsOperator_07) - type: type parameter with/without
allows ref struct, with/withoutstructconstraint,where T : U/whereU : T`
- value:
-
ispattern:value is Type t(seeIsPattern_*)- see cases from
isoperator above
- see cases from
-
asoperator:value as Type(seeAsOperator_*)- see cases from
isoperator above
- see cases from
- generic type substitution
-
ref structsubstituted for type parameter- without
allows ref struct - with
allows ref struct - with satisfied interface constraints
- with unsatisfied interface constraints
- with valid variance (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, ImplementAnInterface_05_Variance)
- with invalid variance (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, ImplementAnInterface_12_Variance_ErrorScenarios)
- without
- type parameter with
allows ref structsubstituted for type parameter (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, ImplementAnInterface_03)- see cases above
- type parameter without
allows ref structsubstituted for type parameter (ConstraintsCheck_04)- see cases above
-
delegatetype variance (...?)
-
- field / auto-property using type parameter with
allows ref struct- instance field / auto-propertyin
ref struct(allowed) - instance field / auto-propertyin
struct,class(disallowed) -
staticfield / auto-property (disallowed) -
recordprimary constructor parameter (disallowed) -
ref structprimary constructor parameter (disallowed)
- instance field / auto-propertyin
- using type parameter with
allows ref struct(extendIsRefLikeTypechecks)- value in anonymous type initializer (disallowed)
- in LINQ query with implicit anonymous type
- value in
makeref(disallowed) - type of
reffield (disallowed) - array element type (disallowed)
- inline array element type (disallowed)
-
asyncparameter type (disallowed) - value in expression tree (disallowed)
- delegate receiver (disallowed)
- conditional access
?.result type, withstructconstraint (disallowed) - conditional access
?.receiver type, withoutstructconstraint - type argument to
dynamiccall (disallowed) - receiver to
dynamiccall (disallowed) - captured in lambda or local function (disallowed)
- error for method signature with
T?whenwhere T : struct, allows ref struct(ConstraintsCheck_06)
- ref safety analysis for instance of
allows ref struct(extendIsRefLikeTypechecks)-
new T()instance -
scoped Tinstance - cannot assign instance to
staticfield (Field, AutoProperty ?) - cannot create
T[](InArrayType_01) - return only scope (see
Return*) - method arguments must match (see
MethodArgumentsMustMatch_*)
-
-
nullchecking with value of type parameter withallows ref struct(seeNullCheck_*)-
value == null,value != null,!(value == null),!(value != null) -
value is null,value is not null,!(value is null),!(value is not null) -
value == nullwhen type parameter hasstructconstraint
-
- object creation:
new T()(seeObjectCreation_*)- with object initializer
- within object initializer
- with
structconstraint - with
Activator.CreateInstance<T>()with/withoutallows ref struct(seeSystemActivatorCreateInstance_*) - collection expression target type
-
scopedwith type parameter withallows ref struct- local
- method parameter
- lambda and local function parameters (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, ScopedTypeParameter_01)
-
params Timplicitlyscoped -
scopedmismatch inoverride -
scopedmismatch inpartialmethod (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, ScopedTypeParameter_03) -
scopedmismatch in delegate (Fill some gaps in Test Plan for "Ref Struct Interfaces" feature #74389, ScopedTypeParameter_04)
-
[UnscopedRef]on interface members (seeUnscopedRefIn*)- language version:
[UnscopedRef]on interface members, interface implementations - on interface methods, properties, indexers, accessors
- on member with no modifier,
abstract,virtual,sealed - implemented on
class,struct,ref struct,interface - implemented explicitly (UnscopedRefInImplementation_*)
- implemented implicitly with/without
[UnscopedRef](UnscopedRefInImplementation_*) - diagnostic for unsafe
[UnscopedRef]mismatch with implicit implementation - ref safety analysis at callsite with instance of interface constrained/not constrained to
struct(seeMethodArgumentsMustMatch_*, etc. cloned from RefFieldTests.cs) - defensive copy with instance of interface constrained/not constrained to
struct(seeDefensiveCopy_*)
- language version:
-
using: implementingIDisposableand/or patternDispose()(seeUsing_*)- with
ref structimplementing interface with/without pattern - with type parameter with
allows ref structimplementing interface and/or pattern, with/withoutstructconstraint
- with
-
foreach(seeForeach_*)-
IEnumerable: see cases inusingabove -
IEnumerable<T>: see cases inusingabove -
IEnumerator: see cases inusingabove -
IEnumerator<T>: see cases inusingabove -
IDisposable: see cases inusingabove
-
-
await using(seeAwaitUsing_*)-
IAsyncDisposable: see cases inusingabove
-
-
await foreach(seeAwaitForeach_*)-
IAsyncEnumerable<T>: see cases inusingabove -
IAsyncEnumerator<T>: see cases inusingabove (is explicit implementation only tested?) (AwaitForeach_IAsyncEnumerableT_03?) -
IAsyncDisposable: see cases inusingabove
-
- anonymous delegates (see
AnonymousDelegateType_*)- with
ref structparameter types - with
allows ref structparameter types -
System.Func<>andSystem.Action<>with/withoutallows ref structconstraints - synthesized delegate type parameter has
allows ref structconstraint if needed
- with
-
-langversion:12and earlier: consuming generic types and methods with type parameters withallows ref struct- construct generic type with non
ref struct(ConstraintsCheck_07) - call generic method with non
ref struct(ConstraintsCheck_02)
- construct generic type with non
- public API
-
ITypeParameterSymbol.AllowsRefLikeType -
RuntimeCapability.ByRefLikeGenerics
-
- VB
- public API supported
- consuming generic types and methods with type parameters with
allows ref struct- construct generic type with non
ref struct(AllowsConstraint_01) - call generic method with non
ref struct(AllowsConstraint_01)
- construct generic type with non
- error overriding or implementing generic methods with type parameters with
allows ref struct
- open questions for Language Design
-
allowsorallow? - other open questions?
-
Productivity
- Colorization for
allows ref struct - completion for
allows ref struct- for
allows(with AddAllowsKeywordRecommendertoKeywordCompletionProvider#73608 in place) - for
ref - for
struct
- for
- Language version upgrade is offered
- F1 for
allows ref struct(tracked byF1help forallows ref structconstraint #74604)- on
allows(doesn't work at the moment) - on
ref(goes to a wrong page at the moment) - on
struct(goes to a wrong page at the moment)
- on
- Hovering over a declaration displays the constraint in the tooltip.
- Implement interface on
ref struct- implicitly
- explicitly
- GoToImplementation on an interface finds implementation on a
ref struct - GoToImplementation on an interface method finds implicit/explicit implementation within a
ref struct - FindAllReferences on an interface finds implementation on a
ref struct - FindAllReferences on an interface method finds implicit/explicit implementation within a
ref struct - GoToDefinition on an interface implemented by a
ref structgoes to the interface - GoToDefinition on an implicit/explicit implementation of an interface method within a
ref structgoes to the method in the interface - completion for
overrideof generic method withallows ref structconstraint is offered and generates correct code - GoToImplementation on a virtual generic method with
allows ref structconstraint finds an override - FindAllReferences on a virtual generic method with
allows ref structconstraint finds a call site - GoToDefinition on an override goes to the overridden generic method with
allows ref structconstraint - Implement generic interface method with
allows ref structconstraint- implicitly (doesn't copy the
allows ref structconstraint at the moment) (tracked by Implement generic interface method withallows ref structconstraint #74605) - explicitly
- implicitly (doesn't copy the
- GoToImplementation on a generic method with
allows ref structconstraint finds an explicit/implicit implementation - FindAllReferences on a generic method with
allows ref structconstraint finds an explicit/implicit implementation - GoToDefinition on an explicit/implicit implementation goes to the implemented generic method with
allows ref structconstraint
kyoyama-kazusa
Metadata
Metadata
Assignees
Labels
Area-CompilersFeature - RefStructInterfaces`allows ref struct` (ref struct interfaces)`allows ref struct` (ref struct interfaces)