dotnet/roslyn

Should provide more specific error message when cardinality of a tuple literal doesn't match target tuple type.

Open

#11.281 aperta il 12 mag 2016

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-CompilersBugConcept-Diagnostic ClarityFeature - TuplesLanguage-C#help wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

        [Fact]
        public void TupleTypeMismatch_01()
        {
            var source = @"
class C
{
    static void Main()
    {
        (int, string) x = (1, ""hello"", 2);
    }
}
" + trivial2uple + trivial3uple;

            CreateCompilationWithMscorlib(source, parseOptions: TestOptions.Regular.WithTuplesFeature()).VerifyDiagnostics(
                // (6,27): error CS0029: Cannot implicitly convert type '(int, string, int)' to '(int, string)'
                //         (int, string) x = (1, "hello", 2);
                Diagnostic(ErrorCode.ERR_NoImplicitConv, @"(1, ""hello"", 2)").WithArguments("(int, string, int)", "(int, string)").WithLocation(6, 27));
        }

Expected: An error message saying cardinality doesn't match.

Guida contributor