Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden Option<T> by disallowing null value #6426

Merged
merged 4 commits into from
Feb 21, 2023

Conversation

Arkatufus
Copy link
Contributor

Fixes #4604

Hardens Option

Changes

  • Make Option<T> constructor throw an ArgumentNullException when null value is passed in
  • Add a Create static method that returns a None when null is passed in

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -5122,10 +5122,12 @@ namespace Akka.Util
public struct Option<T>
{
public static readonly Akka.Util.Option<T> None;
[System.ObsoleteAttribute("Use Option<T>.Create() instead")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -50,7 +58,7 @@ public Option(T value)
/// </summary>
/// <param name="value">The object to convert</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator Option<T>(T value) => new Option<T>(value);
public static implicit operator Option<T>(T value) => Create(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should enable nullable in the future for this project - there's ways to do it in increments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to harden Option<T> to avoid gotcha bugs
2 participants