Open cston opened 5 years ago
Just to clarify, this is because anonymous types are readonly, so we can treat their "type parameters" as out
.
From discussion with Andy, anonymous types are not variant and there is no conversion defined.
static void F2<T>()
{
var c = new { G = new object() };
var d = new { G = "" };
d = c; // error CS0029: Cannot implicitly convert type '<anonymous type: object G>' to '<anonymous type: string G>'
}
We can't do variance on non-interface types. For nullability, we could do special-case a design, but that would need an explicit design decision from LDM.
Should not warn on the following assignments: