dmd
dmd copied to clipboard
Misleading indicator for missing `const` on member functions
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() { }
^