Thread overview
[Issue 6588] New: Struct d'tors + immutable elements doesn't work
Sep 01, 2011
David Simcha
Sep 03, 2011
Kenji Hara
Apr 27, 2012
SomeDude
Nov 11, 2012
Marco Leise
September 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6588

           Summary: Struct d'tors + immutable elements doesn't work
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com
            Blocks: 6587


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2011-09-01 06:36:00 PDT ---
struct Task(Args...) {

    Args _args;

    this(Args args) {
        _args = args;
    }

    ~this() {}  // Bug goes away without this.

}

alias Task!(int function(immutable int), immutable(int)) F;

Error: can only initialize const member __args_field_1 inside constructor Error: this is not mutable

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 03, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6588



--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-03 07:03:19 PDT ---
This is built-in opAssign issue.

When struct has only dtor, built-in opAssign is implemented automatically by compiler with memberwise assign.

struct Task(Args...) {

    Args _args;

    this(Args args) {
        _args = args;
    }

    ~this() {}  // Bug goes away without this.

    // Inserted automatically by compiler.
    // This code does not have file positions, so error message displays
    // no position.
    ref typeof(this) opAssign(typeof(this) rhs)
    {
        this._args = rhs.args;
        // immutable field assign outside constructor causes error
        return this;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6588


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #2 from SomeDude <lovelydear@mailmetrash.com> 2012-04-27 14:18:26 PDT ---
Compiles on 2.059 Win32

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6588


Marco Leise <Marco.Leise@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Marco.Leise@gmx.de


--- Comment #3 from Marco Leise <Marco.Leise@gmx.de> 2012-11-10 17:04:42 PST ---
(In reply to comment #1)

Thanks I think in my case I can then implement opAssign to skip the assignment of immutable fields. Here is a real short test case without templates:

struct Bug6588 {
  immutable int x;
  ~this() {}
}

Also this is related:

struct Bug6588 {
  immutable int x;
  ref Bug6588 test() { return this; }  // this is not mutable
  ref const(Bug6588) test() { return this; }  // ok
}

The compiler has a hard time with partial const/immutable structures.

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