Skip to content

Default parameters of interface type are silently set to null for string constants #59789

@grayed

Description

@grayed

Version Used:
4.1.0-5.22109.6 (0c82c41)

Steps to Reproduce:
The following minimal code demonstrates the problem:

record Foo(IEnumerable<char> Bar = "x");
var f = new Foo();
Assert.IsNotNull(f.Bar);

Same happens in any method with default argument of interface type that System.String implements.
The usage of System.Object as argument type fails, though.

Expected Behavior:
Either method argument set to the given non-null constant value, or compiler error is raised (like for System.Object case right now).

Actual Behavior:
Method argument silently set to null.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions