pvs-studio

Using DateTimeKind on DateTime triggers V3058


var dict1 = new Dictionary<DateTime, int>()
{
    [new DateTime(0, DateTimeKind.Utc)] = 0,
    [new DateTime(1, DateTimeKind.Utc)] = 1
}

dict1 triggers V3058 "V3058 An item with the same key '1' has already been added.".

https://www.viva64.com/en/w/V3058/ states that it warns about issues, that will cause an ArgumentException. This is clearly not the case here as the keys are different.

Leaving out DateTimeKind.UTC from the ctors stops triggering V3058.

var dict2 = new Dictionary<DateTime, int>()
{
    [new DateTime(0)] = 0,
    [new DateTime(1)] = 1
}

Solution

  • Thanks for your feedback! We will fix the issue and let you know about the results. PVS-Studio Team.