www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22134] New: Deprecate returning a void value from a function

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

          Issue ID: 22134
           Summary: Deprecate returning a void value from a function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

For example: libdparse has an opIndex returning the value of a `void[]`.

https://github.com/dlang-community/libdparse/blob/fbdf71b929a9f9bc982d0204f921371806e5d412/src/dparse/stack_buffer.d#L73-L82

---
struct StackBuffer
{
    auto opIndex(size_t i)
    {
        return arr[i];
    }

private:
    void[] arr;
}
---

This is clearly a dead function, as any use of it will result in the error:
---
Error: variable `var` type void is inferred from initializer
`buf.opIndex(0LU)`, and variables cannot be of type void
Error: expression buf.opIndex(0LU) is void and has no value
---

--
Jul 21