www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13905] New: calls to mutable methods are just ignored when

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

          Issue ID: 13905
           Summary: calls to mutable methods are just ignored when
                    instance is an enum
           Product: D
           Version: unspecified
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: minor
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: kanael weka.io

the following code compiles and runs, and prints '10' twice.
I expect it not to compile, since x is an enum.
If x is declared as 'immutable S', it does not compile.

import std.stdio;

struct S {
    uint value;
    void setValue(uint v) {
        value = v;
    }
}

int main() {
    enum S x = S(10);

    writeln(x);
    x.setValue(20);
    writeln(x);
    return 0;
}

--
Dec 28 2014