diff --git a/IDE/mintest/minlib/src/System/Result.bf b/IDE/mintest/minlib/src/System/Result.bf index 8970c658..7b5da210 100644 --- a/IDE/mintest/minlib/src/System/Result.bf +++ b/IDE/mintest/minlib/src/System/Result.bf @@ -2,9 +2,10 @@ namespace System { enum Result : IDisposable { - case Ok(T _val); - case Err(void _err); + case Ok(T val); + case Err(void err); + [Inline] T Unwrap() { switch (this) @@ -17,6 +18,14 @@ namespace System } } + public T Value + { + get + { + return Unwrap(); + } + } + public static implicit operator Result(T value) { return .Ok(value); @@ -66,19 +75,19 @@ namespace System } [SkipCall] - public static void NoDispose() + static void NoDispose() { } - public static void NoDispose() where TVal : IDisposable + static void NoDispose() where TVal : IDisposable { Internal.FatalError("Result must be disposed", 1); } public void ReturnValueDiscarded() { - if (this case .Err) + if (this case .Err(let err)) Internal.FatalError("Unhandled error in result", 1); NoDispose(); } @@ -93,18 +102,6 @@ namespace System } } - /*extension Result where T : class - { - public static T operator?(Self val) - { - switch (val) - { - case .Ok(let inner): return inner; - case .Err: return default; - } - } - }*/ - enum Result : IDisposable { case Ok(T val); @@ -117,15 +114,19 @@ namespace System case .Ok(var val): return val; case .Err(var err): { - String errStr = scope String(); - err.ToString(errStr); - String showErr = scope String(); - showErr.ConcatInto("Unhandled error in result:\n ", errStr); - Internal.FatalError(showErr, 2); + Internal.FatalError("Unhandled error in result"); } } } + public T Value + { + get + { + return Unwrap(); + } + } + public static implicit operator Result(T value) { return .Ok(value); @@ -175,12 +176,12 @@ namespace System } [SkipCall] - public static void NoDispose() + static void NoDispose() { } - public static void NoDispose() where TVal : IDisposable + static void NoDispose() where TVal : IDisposable { Internal.FatalError("Result must be disposed", 1); } @@ -189,13 +190,10 @@ namespace System { if (this case .Err(var err)) { - String errStr = scope String(); - err.ToString(errStr); - String showErr = scope String(); - showErr.ConcatInto("Unhandled error in result:\n ", errStr); - Internal.FatalError(showErr, 1); + Internal.FatalError("Unhandled error in result"); } NoDispose(); + NoDispose(); } }