Skip to content

Abstract method parameter default values do not get nullability warnings #48847

@RikkiGibson

Description

@RikkiGibson

Version Used: d5931e0

Steps to Reproduce:

#nullable enable

public abstract class C
{
    public abstract void M1(string s = null);
}

public delegate void Del1(string s = null);

SharpLab

Expected Behavior: Warnings on the parameter default values for M1 and Del1.

Actual Behavior: No warnings.

Basically, it seems that when the method has no body, we entirely fail to analyze its parameter default values. It suggests that the approach to synthesize the parameter default values and pretend to assign them in NullableWalker is not quite right. When a parameter default value is included in syntax, it may be associated directly with a varying number of method bodies:

  • 0 for delegates and abstract methods
  • 1 for ordinary methods
  • 2 for indexers with get and set accessors

edit: Expected behavior of this scenario has changed based on the proposal nullable-parameter-default-value-analysis.md

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions