dotnet / dotnet/csharpstandard

12.7.11.7 - equivalence of anonymous types

Open
#145 3 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

13.7.11.7 says

> Within the same program, two anonymous object initializers that specify a sequence of properties of the same names and compile-time types in the same order will produce instances of the same anonymous type.

OK, that tells me when the types are the same. But it doesn't tell me when the types are different.

There is nothing in the spec to hint at whether the following should be allowed or not

``` cs
class Program
{
public static void Main()
{
var a1 = new { X = (List)null, };
var a2 = new { X = (List)null, };
a1 = a2; // conversion exists?
a2 = a1; // conversion exists?
}
}
```

Roslyn allows these assignments, even though it understands that the anonymous types are distinct. Should the specification say something to permit it?

A similar issue exists for array types.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.