dotnet/roslyn

Invalid IDE0059 When using constant inside static local function

オープン

#44,948 opened on 2020/06/08

 (3 件のコメント) (2 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-IDEBugFeature - IDE0059help wanted

Repository metrics

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

説明

Version Used: Visual Studio 16.6.1

Steps to Reproduce:

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var local = FormatDate(DateTime.Now);
            var utc = FormatUtcDate(DateTime.Now);
            Console.WriteLine("{0} -> {1}", local, utc);
            Console.ReadKey();

            const string DatePickerFormat = "MM/dd/yyyy hh:mm";
            static string FormatDate(DateTime? date) => date?.ToString(DatePickerFormat);
            static string FormatUtcDate(DateTime? date) => date?.ToUniversalTime().ToString(DatePickerFormat);
        }
    }
}

Expected Behavior: No IDE0059 notice will be shown for DatePickerFormat because it is used by the static local functions FormatDate and FormatUtcDate.

Actual Behavior: An IDE0059 notice is shown for DatePickerFormat .

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