www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19143] New: error or warn when assigning `this.foo = foo`


          Issue ID: 19143
           Summary: error or warn when assigning `this.foo = foo` when the
                    lone foo is this.foo (i.e.not a constructor parameter)
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: iamthewilsonator hotmail.com

struct Foo
    int i;
    this (int ii)
        this.i = i;

void main()
    auto foo = Foo(2);
    import std.stdio : writeln;
    writeln(foo); // prints Foo(0);

should error or at least warn. It leads to very confusing behaviours (you think
i is assigned but its not).

Aug 06 2018