View mode: basic / threaded / horizontal-split · Log in · Help
January 08, 2013
[Issue 9281] New: Enum struct with op overloading doesnt works
http://d.puremagic.com/issues/show_bug.cgi?id=9281

          Summary: Enum struct with op overloading doesnt works
          Product: D
          Version: D2
         Platform: All
       OS/Version: All
           Status: NEW
         Severity: regression
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: kozzi11@gmail.com


--- Comment #0 from Daniel Kozak <kozzi11@gmail.com> 2013-01-08 01:42:33 PST ---
module main;

import std.algorithm;
import std.array;

immutable struct Column {
   string opAssign(V)(V tValue) {
       return tValue;
   }
}

immutable test1 = Column();
enum test2 = Column(); 

void main(string[] args)
{
   string where = test1 = "something"; // works ok
   std.stdio.writeln(where);
   where = test2 = "something else"; // works 2.060, dont compile on 2.061
   std.stdio.writeln(where);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 10, 2013
[Issue 9281] Enum struct with op overloading doesnt works
http://d.puremagic.com/issues/show_bug.cgi?id=9281



--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2013-01-10 06:22:48 PST ---
Did this really work with 2.060? I cannot reproduce the "works 2.060".

Column.opAssign is an immutable member function, then we can call it from
immutable object test1, but cannot call from mutable object test2.

So, the error in test2 = "something else" is correct, as far as I know.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 10, 2013
[Issue 9281] Enum struct with op overloading doesnt works
http://d.puremagic.com/issues/show_bug.cgi?id=9281



--- Comment #2 from Daniel Kozak <kozzi11@gmail.com> 2013-01-10 07:42:45 PST ---
(In reply to comment #1)
> Did this really work with 2.060? I cannot reproduce the "works 2.060".
> 
> Column.opAssign is an immutable member function, then we can call it from
> immutable object test1, but cannot call from mutable object test2.
> 
> So, the error in test2 = "something else" is correct, as far as I know.

Yes my fault, I try to simplify too much. Here is more detailed description

Code which works on 2.060 and don`t compile on 2.061

module main;

import std.algorithm;
import std.array;

immutable struct Column {

   string opAssign(V)(V tValue) {
       return tValue;
   }
}

class Ob2 {
   enum : Column {
       COLUM_A = Column()
   }

   immutable COLUMNS = [
       COLUM_A,
   ];
}

immutable test1 = Column();

void main(string[] args)
{
   string where = test1 = "something"; // works ok
   std.stdio.writeln(where);
   where = (Ob2.COLUM_A = "something else"); // works 2.060, dont compile on
2.061
   std.stdio.writeln(where);
}


However I find out more interesing thing. This code is almost same however it
doesn`t work on 2.061 neither 2.060:

module main;

import std.algorithm;
import std.array;

immutable struct Column {

   string opAssign(V)(V tValue) {
       return tValue;
   }
}

class Ob2 {
   enum : Column {
       COLUM_A = Column()
   }

   // comment this code make it not compilable in 2.060
   /*immutable COLUMNS = [
       COLUM_A,
   ];*/
}

immutable test1 = Column();

void main(string[] args)
{
   string where = test1 = "something"; // works ok
   std.stdio.writeln(where);
   where = (Ob2.COLUM_A = "something else"); // dont compile on 2.060 and
2.061
   std.stdio.writeln(where);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 11, 2013
[Issue 9281] Enum struct with op overloading doesnt works
http://d.puremagic.com/issues/show_bug.cgi?id=9281



--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2013-01-10 22:52:17 PST ---
(In reply to comment #2)
> Yes my fault, I try to simplify too much. Here is more detailed description
> 
> Code which works on 2.060 and don`t compile on 2.061
> 
[snip]

The reason why (Ob2.COLUM_A = "something else") doesn't work in 2.061 is same
as in comment #1. typeof(Ob2.COLUM_A) is a mutable Column, and cannot call
immutable opAssign from that.

> However I find out more interesing thing. This code is almost same however it
> doesn`t work on 2.061 neither 2.060:
> 
[snip]

I think this _was_ an accepts-invalid bug in 2.060.
If you define Ob2.COLUMNS in 2.060, Ob2.COLUM_A is _incorrectly_ typed as
immutable(Column). This is definitely a bug (But I don't know what change is
fixed the bug in 2.060).

So, this is not a regression.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 11, 2013
[Issue 9281] Enum struct with op overloading doesnt works
http://d.puremagic.com/issues/show_bug.cgi?id=9281


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

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


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2013-01-10 23:16:33 PST ---
(In reply to comment #3)
> I think this _was_ an accepts-invalid bug in 2.060.
> If you define Ob2.COLUMNS in 2.060, Ob2.COLUM_A is _incorrectly_ typed as
> immutable(Column). This is definitely a bug (But I don't know what change is
> fixed the bug in 2.060).

I found a commit which the behavior is changed.

https://github.com/D-Programming-Language/dmd/commit/e01eb59f842dfe7a5275d96c420691c4a64f57f4

The root cause of the bug 5779 was an optimizer bug. 
If the type of an optimized result is different from the type of a source
expression, the source expression type had been accidentally modified.

In this case, the declaration of COLUMNS invokes optimizer on the expression [
COLUM_A, ], and it accidentally modified the type of COLUM_A to
immutable(Column).

So the conclusion is: the original code had an accepts-invalid bug, and it was
already fixed in 2.061.

I'll mark this as "resolved-invalid" bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home