D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3893 - opOpAssign and opIndexOpAssign get wrong operator string
Summary: opOpAssign and opIndexOpAssign get wrong operator string
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2010-03-08 01:52 UTC by Lars T. Kyllingstad
Modified: 2014-02-15 02:43 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lars T. Kyllingstad 2010-03-08 01:52:06 UTC
The specification says:

    The expression: a op= b
    is rewritten as: a.opOpAssign!("op")(b)

A similar statement is made about opIndexOpAssign. However, what actually happens is that the template parameter is set to "op=", as this program shows:

    struct S
    {
        void opIndexOpAssign(string op)(int x, int i)
        {
            pragma (msg, op);
        }

        void opOpAssign(string op)(int x)
        {
            pragma(msg, op);
        }
    }

    void main()
    {
        S s;
        s[1] += 2;
        s += 3;
    }

This prints the following on compilation:

  +=
  +=
Comment 1 Lars T. Kyllingstad 2010-03-25 07:59:53 UTC
The documentation has been fixed for opOpAssign, but not for opIndexOpAssign or opSliceOpAssign.
Comment 2 Lars T. Kyllingstad 2010-03-25 08:01:43 UTC
Downgrading importance since, apparently, the spec is wrong and not the compiler.
Comment 3 Lars T. Kyllingstad 2010-08-16 04:46:16 UTC
The spec was right all along, and the compiler was fixed with DMD 2.047.