Bug 10168 – Named tuple: inconsistent behavior

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-25T18:07:00Z
Last change time
2014-04-24T12:34:11Z
Assigned to
nobody
Creator
r.97all

Comments

Comment #0 by r.97all — 2013-05-25T18:07:05Z
The code at the bottom outputs > S(314159265) > S(0) in DMD 2.062, http://dpaste.1azy.net/96d42b70 but > S(0) > S(314159265) in another version, http://dpaste.1azy.net/edc065ea I think right output is S(314159265) repeated 2 times. ----- import std.stdio; import std.typecons : Tuple; struct S { int x; Tuple!(S, "x") toTuple() { return Tuple!(S, "x")(this); } } void main() { auto y = S(314159265).toTuple(); y[0].writeln(); y.x.writeln(); }
Comment #1 by bearophile_hugs — 2013-05-26T05:30:08Z
Also this similar program gives an unusual error message: import std.stdio: writeln; import std.typecons: Tuple; struct Foo { int x; Tuple!(Foo, "x") toTuple() { return Tuple!(Foo, "x")(this); } } void main() { auto y = Foo(100).toTuple; y[1].writeln; // line 11 y.x.writeln; } temp.d(11): Error: no [] operator overload for type Tuple!(Foo, "x")
Comment #2 by andrej.mitrovich — 2014-04-24T12:25:30Z
Original case fixed, but bearophile's post is another issue which I'll file now.
Comment #3 by andrej.mitrovich — 2014-04-24T12:34:11Z
(In reply to Andrej Mitrovic from comment #2) > Original case fixed, but bearophile's post is another issue which I'll file > now. Filed as https://issues.dlang.org/show_bug.cgi?id=12632