Summary: const-violation in struct error message
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-07-02 05:31:17 PDT ---
This D2 program is wrong, because the rnd field of Foo must change its state,
so it can't be called in a const method bar():

import std.random: MinstdRand, uniform;
struct Foo {
    MinstdRand rnd;
    int bar() const {
        return uniform(0, 10, rnd);
void main() {}

But dmd v2.047 shows bad error messages:

...\dmd\src\phobos\std\random.d(684): Error: function
() is not callable using argument types ()
...\dmd\src\phobos\std\random.d(685): Error: function
() is not callable using argument types ()
...\dmd\src\phobos\std\random.d(5): Error: template instance
error instantiating

A better single error message can just say that uniform(_, _, rnd) can't be
called inside bar() because uniform() tries to mutates rnd while bar is const.

See also bug 4416

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to