Skip to content

Use symbol to signal uninitialized message fields #146

Open
@JimLarson

Description

@JimLarson

We recently had a customer question on how to conditionally set a field, wanting to do something like: MyProto{ my_field: x ? some_value : null }. If the field is scalar, the conditional alternative can be the default value. If there is only one conditionally-set field, the conditional can be lifted up at the cost of duplicating the initialization of the other fields. But for multiple conditionally-set message fields, or lots of duplication, we have no good solution, other than the standard cop-out of an extension function.

Given that we're using null to signal a read from an unset field for wrapper types, we should consider using null for indicating "don't set this field" for message types. We'd have to do some work on the type checker to make this legal.

There is some ambiguity for Value fields: does MyProto { value_field: null } mean unset or set to the null_value option?

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