Skip to content
Commit Detail

Commit 64b59bc

Author
Justin Mazzola Paluska <jmp@cloudflare.com> 2024-04-30 08:48:27 -0400
Parents
855279a
Tree
6d70e3b
Reset kj::Maybes with `kj::none` instead of `{}`

The capnproto pull request
https://github.com/capnproto/capnproto/pull/2014 adds another
assignment operator for Maybes.  With a version of capnproto including
that PR, we get compilation errors of the form:

```
external/workerd/src/workerd/io/worker.c++:2524:15: error: use of overloaded operator '=' is ambiguous (with operand types 'kj::Maybe<InspectorChannelImpl &>' and 'void')
      channel = {};
      ~~~~~~~ ^ ~~
bazel-out/k8-dbg/bin/external/capnp-cpp/src/kj/_virtual_includes/kj/kj/common.h:1679:17: note: candidate function
  inline Maybe& operator=(decltype(nullptr)) { ptr = nullptr; return *this; }
                ^
bazel-out/k8-dbg/bin/external/capnp-cpp/src/kj/_virtual_includes/kj/kj/common.h:1682:17: note: candidate function
  inline Maybe& operator=(T* other) { ptr = other; return *this; }
                ^
```

The Maybes that I fixed in this PR are all reference
types (`Maybe<T&>`), so I’m not sure what assigning `{}` would do,
since if it’s assigning a temporary, the reference will be garbage.

However, in the three cases here, we seem to be resetting the objects,
so assigning `kj::none` is correct.

Files changed

1 file changed~1 modified