dotnet/roslyn
Default value of a struct type should give nullable initial state to some field-backed properties
开放
#84,987 创建于 2026年8月20日
Area-CompilersFeature - Nullable Reference Typeshelp wanted
仓库指标
- 星标
- (20,414 个星标)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 256 个 PR)
描述
The current behavior is dependent on whether we are currently constructing the struct instance, and feels a little inconsistent.
Basically, it feels like we should be able to get a similar behavior for member flow states, when any default value of a struct type is used, as when we are working out the initial state of struct fields in a constructor.
Note that 'null-resilient' properties using field keyword would be excepted from this. Their initial flow state would be the same as the property. Currently working on a change to make that work more consistently in constructors. (resolving #77991).
I consider this issue low priority
struct S
{
public void M()
{
this = default;
this.Prop2.ToString(); // no warning
}
public S()
{
this = default;
Prop2.ToString(); // warning
}
public string Prop2 { get; set; }
}