dotnet/roslyn

Bad error message on const ref fields

オープン

#17,125 opened on 2017/02/14

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersBugConcept-Diagnostic ClarityFeature - Ref Locals and Returnshelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Valid code:

static void Test(int x)
{
    ref int y = ref x;
}

Invalid code:

static void Test(int x)
{
    const ref int y = ref x;
}

Expected: an error message on const specifying that you cannot use ref and const modifiers together.

Found: parser fails with the following errors:

image

  1. CS1525 Invalid expression term 'ref'
  2. CS1002 ; expected
  3. CS1001 Identifier expected
  4. CS8172 Cannot initialize a by-reference variable with a value
  5. CS0118 'x' is a variable but is used like a type
  6. CS8174 A declaration of a by-reference variable must have an initializer

コントリビューターガイド