[Issue 23998] @mustuse should require opCast(T:bool) is checked

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 18 11:02:50 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23998

--- Comment #2 from Richard Cattermole <alphaglosined at gmail.com> ---
Okay lets say we have an error struct:

```d
@mustuse struct Result(T) {
   private T* value;

   bool isNull() {
       return value is null;
   }

   ref T get() {
       return *value;
   }

   alias get this;
}
```

We pass it into our function somehow (in this case I'll go with a parameter):

```d
void myFunction(Result!int arg) {
    writeln(arg.get);
}
```

Great, you use the variable! But the whole reason for @mustuse is so that we
can guarantee that error checks have been handled in some way.

So we want some way for a function (like the isNull in the above example) to
have to be checked, not just a method being called.

Without this, you will end up with runtime errors instead of compiler ones
(like I have been experiencing).

--


More information about the Digitalmars-d-bugs mailing list