Skip to content

Tuple conversion are incorrectly specified #1155

@333fred

Description

@333fred

Describe the bug

The compiler implements both a tuple type conversion, and a tuple literal conversion from expression. The spec currently only covers that latter conversion. As a concrete example of a feature that explicitly designed for and allowed, but the spec says is illegal:

short s = 1;

(int, int) t1 = (s, s); // As said in the spec, this is a tuple expression conversion
(short, short) t2 = (s, s);
(int, int) t3 = t2; // By the spec, there shouldn't be a conversion here, but the compiler allows a tuple type conversion from (short, short) to (int, int)

Specifically, https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/conversions.md#10213-implicit-tuple-conversions is the only conversions portion of the specification that touches tuples, and it covers tuple expressions. These are defined by https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/expressions.md#1286-tuple-expressions. In t3 = t2, t2 is not a tuple expression, but is instead a simple name: https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/expressions.md#1284-simple-names; since we're not dealing tuple expressions, implicit tuple conversions don't apply, and the spec says that no conversion should exist from t2 to t3.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions