www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11270] New: [REG 2.064] Initialization of struct in constructor

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11270

           Summary: [REG 2.064] Initialization of struct in constructor
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code benjamin-thaut.de


--- Comment #0 from Benjamin Thaut <code benjamin-thaut.de> 2013-10-15 02:25:27
PDT ---
The following code used to work dmd 2.064 beta 1 and all versions before that.
It just broke on the latest version of the 2.064 branch on git. 

repro.d(13): Error: cannot implicitly convert expression (f) of type float to
netvar!float

Although I'm not really sure if this is a bug or if the code is invalid and
just used to work because of other bugs.


Repro case:

struct netvar(T) {
    T value;
    alias value this;

    void opAssign(T newVal){
        value = newVal;
    }    
}

void main(string[] args)
{
  float f = 2.0f;
  netvar!float f2 = f;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11270



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-10-15 03:59:51 PDT ---
(In reply to comment #0)
 The following code used to work dmd 2.064 beta 1 and all versions before that.
 It just broke on the latest version of the 2.064 branch on git. 
 
 repro.d(13): Error: cannot implicitly convert expression (f) of type float to
 netvar!float
With 2.057-2.063, same error occurs for the code.
 Although I'm not really sure if this is a bug or if the code is invalid and
 just used to work because of other bugs.
As far as I know, the repro case is invalid. On the variable initialization `netvar!float f2 = f;` opAssign never invoked. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11270



--- Comment #2 from Benjamin Thaut <code benjamin-thaut.de> 2013-10-15 04:07:22
PDT ---
Sorry, I reduced the repro case to much. Here is the actual repro case I had
first:

struct netvar(T) {
    T value;
    alias value this;

    void opAssign(T newVal){
        value = newVal;
    }    
}

class Foo
{
  netvar!float f;

  this(float f)
  {
    this.f = f;
  }
}

void main(string[] args)
{
  new Foo(2.0f);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11270



--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2013-10-15 07:02:24 PDT ---
(In reply to comment #2)
 Sorry, I reduced the repro case to much. Here is the actual repro case I had
 first:
 
 struct netvar(T) {
     T value;
     alias value this;
 
     void opAssign(T newVal){
         value = newVal;
     }    
 }
 
 class Foo
 {
   netvar!float f;
 
   this(float f)
   {
     this.f = f;
   }
 }
 
 void main(string[] args)
 {
   new Foo(2.0f);
 }
Ah, this is an expected behavior that has been introduced by fixing bug 9665. With git-head, compiler tries to rewrite `this.f = f;` to the field initialization. Possible modifications: 1. Rewrite this.f = f; to this.f = netvar!float(f); It will initialize the Foo.f by the struct literal. 2. Add a constructor this(T); in netbar struct to accept a T value as a valid initializer. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11270



--- Comment #4 from Benjamin Thaut <code benjamin-thaut.de> 2013-10-15 07:04:49
PDT ---
Thanks for the suggestions. I knew how to fix this, but I just wanted to
confirm that this is indeed intended behavior and not a regression, because it
used to work in all earlier compiler versions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11270


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2013-10-15 07:21:07 PDT ---
(In reply to comment #4)
 Thanks for the suggestions. I knew how to fix this, but I just wanted to
 confirm that this is indeed intended behavior and not a regression, because it
 used to work in all earlier compiler versions.
It was the long standing bug. I'm glad to be able to fix it finally. Mark this issue as resolved invalid. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 15 2013