Skip to content

CC0071 Introduce a field for parameter ignores parameters consumed by base() and this() #1026

@r-pankevicius

Description

@r-pankevicius

There are CC0071 warnings for constructor parameters that are passed to base() or this() constructors. See "OK", "NOT OK" in comments for what's expected.

public class Base
{
	public Base(int x) // CC0071 - OK
	{
	}
}

After fix applied - OK:

public class Base
{
	private readonly int x;

	public Base(int x)
	{
		this.x = x;
	}
}

Let's create a derived class:

public class Derived :Base
{
	public Derived(int x) : base(x) // CC0071 - NOT OK, because x is passed to base ctor
	{
	}
}

Another false flag for this(x):

public class Base
{
	private readonly int x;

	public Base(int x)
	{
		this.x = x;
	}

	public Base(int x, string s) : this(x) // // CC0071 for x - NOT OK, for s - OK
	{
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions