-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Test plan for "field keyword in properties" #57012
Comments
Moving to 17.2. The work for thsi hasn't gotten merged in yet anyways. |
Note to self: The following properties for
|
There are interesting scenarios around overriding virtual properties. public class Base
{
public virtual int P1 { get; set; }
public virtual int P2 { get; set; }
public virtual int P3 { get; set; }
public virtual int P4 { get; set; }
public virtual int P5 { get; set; }
public virtual int P6 { get => 0; set { } }
}
public class Derived : Base
{
// no error.
public override int P1 { get => 0; }
// This produces Auto-implemented properties must have get accessors.
// However, per the spec updates, a set-only with semicolon is allowed.
// Should this now produce an error similar to ERR_AutoPropertyMustOverrideSet?
public override int P2 { set; }
// This synthesizes a sealed setter. Make sure we have this behavior for semi-auto.
public sealed override int P3 { get => 0; }
// Auto-implemented properties must override all accessors of the overridden property.
public override int P4 { get; }
// Will this be allowed? It's not allowed for old-style auto properties (see P4).
public override int P5 { get => field; }
public override int P6 { get => field; }
public Derived()
{
// P6 looks like a property that's assignable through backing field.
// But this shouldn't be the case due to the inherited setter.
// We should use 'GetOwnOrInheritedSetMethod' for the logic of assignability through backing field.
// Add a test to confirm that.
P6 = 10;
}
} Do these scenarios have clear answer as to what's the expected behavior? Are there any that needs to be discussed in LDM? |
Could you add a quote from the relevant portion of the spec?
Please include exact wording of the message.
We probably should treat this as a property with a user provided body. Presence of the |
@Youssef1313 BTW, consider not "polluting" the Test Plan issue with "random" discussions. Open a separate issue for each specific question. |
Championed proposal: dotnet/csharplang#140
Spec: proposals/field-keyword.md
Compiler:
field
keyword@
this.field
,base.field
,Qualifier.field
object P => expr;
nameof()
[Conditional]
FieldKeywordTests.ImplicitAccessorBody_*
)get
,set
,init
interface
class
,struct
,ref struct
,interface
,record*
get
-only,set
-only,init
-only (seeFieldKeywordTests.AutoPropertyMustHaveGetAccessor_*
)field
references in multiple properties: each get private backing fieldfield
) must override all accessors (seeFieldKeywordTests.Override_*
,New_*
)static
field reference instatic
function (seeFieldKeywordTests.Lambda_*
,LocalFunction_*
)FieldKeywordTests.Attribute_*
)ref
returning property (seeFieldKeywordTests.RefReturning_*
)FieldKeywordTests.RestrictedTypes
)FieldKeywordTests.ByRefLikeType_*
)@field
with and without backing fieldColor Color
FieldKeywordTests.PassByReference_*
)field
reference[CompilerGenerated]
(seeFieldKeywordTests.Attribute_03
)[Conditional]
code only (seeFieldKeywordTests.Conditional
) (see open LDM question)[field:]
attributesFieldKeywordTests.Attribute_03
)FieldKeywordTests.Attribute_03
)field
references (seeFieldKeywordTests.PartialProperty_Attribute_03
)[field: Obsolete]
(seeFieldKeywordTests.ObsoleteAttribute
)nameof(field)
nameof(field)
as invocationFieldKeywordTests.Initializer_*
)field
referenceclass
,struct
,ref struct
,interface
FieldKeywordTests.ConstructorAssignment_*
)class
,struct
,ref struct
,interface
struct
backing fields and warnings when property is accessed in constructor (seeFieldKeywordTests.DefaultInitialization_*
)readonly
properties (seeFieldKeywordTests.ReadOnly_*
)initonly
when type, property, or accessor isreadonly
field
inget
,set
accessorsset
accessor inreadonly
context for property usingfield
(see open LDM question) (seeFieldKeywordTests.ReadOnly_01
)FieldKeywordTests.PartialProperty_*
)class
,struct
,ref struct
,interface
,record*
field
in accessorsfield
or auto-implementationfield
references on definition or implementationfield
references on definition and implementationfield
references onreadonly
property or accessor with same or different modifiers on parts[field:]
attributes concatenated across partsAllowMultiple=false
field
and one or both parts havefield:
targeted attribute lists. (See alsoPartialPropertiesTests.Attributes_Property_BackingField
. This issue referenced in source.)WRN_SequentialOnPartialClass
is produced when needed (see also comment)partial
propertiespartial
propertiesFieldKeywordTests.Nullability_*
) Implement nullable analysis forfield
keyword #75244field
has annotations of containing type[field:MaybeNull]
etc. affectfield
NullableWalker.Scan().getFieldSymbolToBeInitialized()
: Is checking IsAutoProperty sufficient or should we check the appropriate accessors are missing or auto-implemented (see comment)?NullableWalker.Scan().getFieldSymbolToBeInitialized()
: Is checking IsAutoProperty sufficient or should we check the appropriate accessors are missing or auto-implemented #75245NullableWalker.TryGetReceiverAndMember()
: callBinder.AccessingAutoPropertyFromConstructor
to matchDefiniteAssignment
implementation (see comment)?GetSymbolInfo(fieldExpr)
returns backing fieldfield
reference in the speculative semantic model Field-backed properties: supportfield
references in speculativeSemanticModel
#75398IOperation
for expression referencingfield
struct
fulfillsunmanaged
constraint and managed type rules (see pointer types) depending on synthesized fieldsfield
keyword #74937Productivity:
field
The text was updated successfully, but these errors were encountered: