-
Notifications
You must be signed in to change notification settings - Fork 292
Closed
Description
Describe the bug
After updating MSTest.TestFramework to 3.0.2 unit tests that use Assert.AreEqual/AreNotEqual with a nullable struct parameter that has an implicit cast operator to the other parameter type implemented don't compile any more.
Steps To Reproduce
- Create a new test project. (It will be created with MSTest.TestFramework 2.2.10.)
- Add the following code.
public struct MyValue
{
public int Value;
public static implicit operator int(MyValue v) => v.Value;
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var v = new MyValue();
MyValue? nullable = null;
// Still compiles without errors.
Assert.AreEqual(0, v);
Assert.AreNotEqual(1, v);
Assert.AreEqual(null, nullable);
Assert.AreNotEqual(v, nullable);
// Doesn't compile any more.
Assert.AreNotEqual(1, nullable);
Assert.AreEqual(0, nullable); // Note: This fails. I don't know if there is a useful use-case for this.
}
}- Try to compile the project, see that it compiles just fine.
- Update MSTest.TestFramework to 3.0.2
- See compile errors
Expected behavior
Code should compile without errors.
Actual behavior
Code has compile errors:
CS0411 The type arguments for method 'Assert.AreNotEqual(T?, T?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Additional context
The Assert.AreEqual case might not make sense. But at least the Assert.AreNotEqual case has valid use-cases and should work.
It seems like the reason for this is #254/#1429 because version 2.2.10 used this overload.
Cc @whoisj @Evangelink
Reactions are currently unavailable