[Issue 15905] New: Tuple Op Assignment Overload incorrect?

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Apr 9 14:25:09 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15905

          Issue ID: 15905
           Summary: Tuple Op Assignment Overload incorrect?
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: pontifechs at gmail.com

I've come across some wonky behavior with a Tuple's *= operator in 2.071.

Here's a sample:



import std.stdio;

import std.typecons;


alias SomeStuff = Tuple!(float, "value");

void main()
{
  auto bob = SomeStuff(-1.0f);            // Prints:
  writeln(bob);                           // Tuple!(float, "value")(-1)
  bob.value *= -1;
  writeln(bob);                           // Tuple!(float, "value")(-1.00002) 
!!!! WRONG !!!!

  auto sue = SomeStuff(-1.0f);
  writeln(sue);                           // Tuple!(float, "value")(-1)
  sue.value = sue.value * -1;
  writeln(sue);                           // Tuple!(float, "value")(1)

  auto interesting = SomeStuff(-1.0f);
  writeln(interesting);                   // Tuple!(float, "value")(-1)
  interesting.value *= -2;
  writeln(interesting);                   // Tuple!(float, "value")(2)        
What?
}


I'm running Arch Linux with DMD 2.071. Downgrading to 2.070 produces the
following correct output:

$ dmd --version; dmd app.d; ./app
DMD64 D Compiler v2.070
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
Tuple!(float, "value")(-1)
Tuple!(float, "value")(1)
Tuple!(float, "value")(-1)
Tuple!(float, "value")(1)
Tuple!(float, "value")(-1)
Tuple!(float, "value")(2)

Same cmd on 2.071 for reference.

$ dmd --version; dmd app.d; ./app
DMD64 D Compiler v2.071.0
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
Tuple!(float, "value")(-1)
Tuple!(float, "value")(-1.00002)
Tuple!(float, "value")(-1)
Tuple!(float, "value")(1)
Tuple!(float, "value")(-1)
Tuple!(float, "value")(2)

--


More information about the Digitalmars-d-bugs mailing list