Skip to content

null messages are skipped. So are None and unit in F# #2414

Description

@Prunkles

I would like to begin with a question: Are null messages actually allowed in this library?
I'm not sure, because I have multiple sources, and they all contradict each other:

  1. The signature of the IContext.Message indicates that messages can be null:

  2. But if you try to send a null message from an actor to another, then the message apparently will be skipped. I digged a bit in sources, and found that I guess is the reason:

    msg = _userMailbox.Pop();
    if (msg is not null)

    So null messages are successfully put in the mailbox, but are discarded during processing.
    But honestly, it seems more like a coincidence rather than a desired behavior. nulls are skipped here because _userMailbox.Pop() returned null, but it will do this, as we see by the code below, in two cases:
    public object? Pop() => _messages.TryDequeue(out var message) ? message : null;

    1. if the mailbox is empty (and this is an intended behavior);
    2. if the message happened to be null by its value.

    So maybe this behavior is actually a bug.

  3. But, in spite of the 2. point, the null messages won't be skipped if they are sent to a Future, because they are not actors, therefore they don't have mailboxes with this strange behavior.

  4. There is a PR prevent null messages #1145 that explicitly says that null messages should not be allowed, but it is in a different context of remote actors, so I am not sure if it is appliable here.


Anyway, this issue is about another problem. In F#, None (option) and () (unit) values are represented as null in runtime. So, if null messages are actually not allowed, then these very general and frequently used types become unusable, efficiently making the whole F# unusable for using this library.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions