diff --git a/BeefLibs/corlib/src/Nullable.bf b/BeefLibs/corlib/src/Nullable.bf index e108676d..8dd3f923 100644 --- a/BeefLibs/corlib/src/Nullable.bf +++ b/BeefLibs/corlib/src/Nullable.bf @@ -121,13 +121,13 @@ namespace System public static bool operator!=(Nullable lhs, TOther rhs) where bool : operator T != TOther { - if (!lhs.mHasValue) return false; + if (!lhs.mHasValue) return true; return lhs.mValue != rhs; } public static bool operator!=(TOther lhs, Nullable rhs) where bool : operator TOther != T { - if (!rhs.mHasValue) return false; + if (!rhs.mHasValue) return true; return lhs != rhs; } diff --git a/IDE/mintest/minlib/src/System/Nullable.bf b/IDE/mintest/minlib/src/System/Nullable.bf index de4516ae..af22b485 100644 --- a/IDE/mintest/minlib/src/System/Nullable.bf +++ b/IDE/mintest/minlib/src/System/Nullable.bf @@ -113,13 +113,13 @@ namespace System public static bool operator!=(Nullable lhs, TOther rhs) where bool : operator T != TOther { - if (!lhs.mHasValue) return false; + if (!lhs.mHasValue) return true; return lhs.mValue != rhs; } public static bool operator!=(TOther lhs, Nullable rhs) where bool : operator TOther != T { - if (!rhs.mHasValue) return false; + if (!rhs.mHasValue) return true; return lhs != rhs; } diff --git a/IDEHelper/Tests/src/NullConditional.bf b/IDEHelper/Tests/src/NullConditional.bf index d696b079..bfdccf8d 100644 --- a/IDEHelper/Tests/src/NullConditional.bf +++ b/IDEHelper/Tests/src/NullConditional.bf @@ -55,7 +55,7 @@ namespace Tests Test.FatalError(); Test.Assert(ca?.mCondB?.mStr == null); - Test.Assert(!(ca?.mCondB?.mStr?.Length != 0)); + Test.Assert(ca?.mCondB?.mStr?.Length != 0); Test.Assert(!(ca?.mCondB?.mStr?.Length == 0)); if (let i = ca?.mCondB?.mInt) diff --git a/IDEHelper/Tests/src/Nullable.bf b/IDEHelper/Tests/src/Nullable.bf index 8d6e3530..57b4dcad 100644 --- a/IDEHelper/Tests/src/Nullable.bf +++ b/IDEHelper/Tests/src/Nullable.bf @@ -31,5 +31,32 @@ namespace Tests Test.Assert(!intn2.TryGetValue(ref i)); Test.Assert(i == 100); } + + [Test] + public static void TestOperators() + { + int? iNull = null; + bool? bNull = null; + + Test.Assert(!(iNull == 0)); + Test.Assert(!(iNull <= 0)); + Test.Assert(!(iNull >= 0)); + + Test.Assert(!(bNull == false)); + Test.Assert(!(bNull == true)); + Test.Assert(bNull != true); + Test.Assert(bNull != false); + + iNull = 100; + bNull = false; + + Test.Assert(iNull >= 50); + Test.Assert(!(iNull >= 150)); + Test.Assert(iNull < 150); + Test.Assert(!(iNull < 50)); + Test.Assert(iNull == 100); + Test.Assert(iNull != 99); + Test.Assert(!(iNull != 100)); + } } }