dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Misleading indicator for missing `const` on member functions

Open Bolpat opened this issue 1 month ago • 0 comments

Example code:

struct S
{
    void doStuff() { }
}
void main()
{
    const S s;
    s.doStuff;
}

Diagnostic:

onlineapp.d(8): Error: mutable method `onlineapp.S.doStuff` is not callable using a `const` object
    s.doStuff;
    ^
onlineapp.d(3):        Consider adding `const` or `inout` here
    void doStuff() { }
         ^

The location the indicator ^ refers to suggests the following edit:

-   void doStuff() { }
+   void const doStuff() { }

This suggestion doesn’t work. Ideally, the indicator would point at the space after the parameter list:

onlineapp.d(8): Error: mutable method `onlineapp.S.doStuff` is not callable using a `const` object
    s.doStuff;
    ^
onlineapp.d(3):        Consider adding `const` or `inout` here
    void doStuff() { }
                  ^

Bolpat avatar Nov 21 '25 11:11 Bolpat