Bug 9580 – std.variant.Algebraic with Tuple format problem
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-23T17:34:00Z
Last change time
2016-04-16T08:01:16Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-02-23T17:34:24Z
import std.variant: Algebraic, This;
import std.typecons: Tuple;
alias Foo = Algebraic!(int, Tuple!(This[]));
void main() {
auto f = Foo(0);
}
DMD 2.063alpha gives:
...\dmd2\src\phobos\std\format.d(1821): Error: static assert (isInputRange!(This[])) is false
...\dmd2\src\phobos\std\format.d(2279): instantiated from here: formatValue!(Appender!(string), This[], char)
...\dmd2\src\phobos\std\typecons.d(551): instantiated from here: formatElement!(Appender!(string), This[], char)
temp.d(3): instantiated from here: Tuple!(This[])
Comment #1 by andrei — 2013-02-23T23:55:44Z
I'm on the road now but a quick test suggests that simply providing an empty definition for This fixes the problem:
struct This {}
Can someone give it a shot?
Comment #2 by bearophile_hugs — 2013-12-27T03:41:21Z
Now the original code compiles with no errors. But if I try to to instantiate a Foo that contains an array of Foos:
import std.variant: Algebraic, This;
import std.typecons: Tuple;
alias Foo = Algebraic!(int, Tuple!(This[]));
void main() {
auto f = Foo(0);
auto f = Foo([Foo(0)]);
}
I see (dmd 2.065alpha):
...\dmd2\src\phobos\std\variant.d(548): Error: static assert "Cannot store a VariantN!(8u, int, Tuple!(This[]))[] in a VariantN!(8u, int, Tuple!(This[]))"
temp.d(6): instantiated from here: __ctor!(VariantN!(8u, int, Tuple!(This[]))[])
Comment #3 by bearophile_hugs — 2013-12-27T04:15:08Z
Sorry, the code in comment2 is wrong. This should be better:
import std.variant: Algebraic, This;
import std.typecons: Tuple, tuple;
alias Foo = Algebraic!(int, Tuple!(This[]));
void main() {
auto f = Foo(tuple([Foo(0)]));
}
The error messages:
...\dmd2\src\phobos\std\variant.d(548): Error: static assert "Cannot store a Tuple!(VariantN!(8u, int, Tuple!(This[]))[]) in a VariantN!(8u, int, Tuple!(This[]))"
temp.d(5): instantiated from here: __ctor!(Tuple!(VariantN!(8u, int, Tuple!(This[]))[]))
Comment #4 by simen.kjaras — 2016-04-16T00:36:45Z
The code in comment 3 compiles great on 2.070. The problem seems to have been solved at some point since new year 2014.