Build the following project which does this:
Assert.NotNull((JsonValue?)(int?)42);
The cast here should treat that int as a nullable reference type JsonValue. It's possible for a badly implemented conversion operator to return null here, which is what we're testing. The analyzer thinks we're checking the integer for null.
C:\scratch\xunitAssert\TestClass.cs(13,13): warning xUnit2002: Do not use Assert.NotNull() on value type 'int'. Remove this assert. [C:\scratch\xunitAssert\xunitAssert.csproj]
If you examine the IL of this method you can see it is indeed calling the operator and passing the result into Assert.Equals(object), so there seems to be a bug in how the analyzer identifies the type passed in. It could be related to implicit casting that happens. To get from int -> JsonValue the compiler discovers the implicit cast to JsonNode. I've recreated an isolated repro here that doesn't use the Json types:
xunitAssert.zip
Build the following project which does this:
The cast here should treat that
intas a nullable reference typeJsonValue. It's possible for a badly implemented conversion operator to returnnullhere, which is what we're testing. The analyzer thinks we're checking the integer fornull.If you examine the IL of this method you can see it is indeed calling the operator and passing the result into
Assert.Equals(object), so there seems to be a bug in how the analyzer identifies the type passed in. It could be related to implicit casting that happens. To get from int -> JsonValue the compiler discovers the implicit cast to JsonNode. I've recreated an isolated repro here that doesn't use the Json types:xunitAssert.zip