[Issue 11984] New: not using opAssign when declaration in different scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 24 09:04:19 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=11984

           Summary: not using opAssign when declaration in different scope
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: luka8088 at owave.net


--- Comment #0 from luka8088 <luka8088 at owave.net> 2014-01-24 09:04:14 PST ---
I am sorry for the (probably) misleading summary but I am myself unsure how to
call it. If S1!(C[]) s1c; declaration is in the constructor then it works, if
it is a class member then the following error pops up:

Error: cannot implicitly convert expression ([new C]) of type C[] to S1!(C[])

-------------------------------

import std.stdio;

struct S1 (T) {

  T v1;

  void opAssign (T v2) {
    v1 = v2;
  }

}

class C {
}

class Broken {

  S1!(C[]) s1c;

  this () {

    static if (__traits(compiles, s1c = [new C()]))
      s1c = [new C()];
    writeln(s1c.v1.length);

  }

}

class Works {

  this () {

    S1!(C[]) s1c;
    s1c = [new C()];
    writeln(s1c.v1.length);

  }

}

void main () {
  new Broken();
  new Works();
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list