Bug 3067 – std.range.chain returns a range of wrong type elements

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-06-13T12:52:00Z
Last change time
2015-06-09T01:27:59Z
Assigned to
bugzilla
Creator
rayerd.wiz
Blocks
5659

Comments

Comment #0 by rayerd.wiz — 2009-06-13T12:52:18Z
import std.stdio; import std.algorithm; import std.range; void main() { f(chain("a")); // immutable(char) <- OK f(chain("a".dup)); // char <-------- ? f(chain("a".dup, "b")); // int <---- NG } void f(Range)(Range r) { writeln(typeid(ElementType!(Range))); }
Comment #1 by rayerd.wiz — 2009-06-13T15:40:47Z
(In reply to comment #0) - f(chain("a".dup)); // char <-------- ? + f(chain("a".dup)); // char <-------- OK
Comment #2 by andrei — 2009-08-27T23:03:45Z
This is a bug in the compiler. Consider: import std.stdio; void main() { auto x = true ? ("a".dup)[0] : "b"[0]; writeln(typeof(x).stringof); } This program prints int, meaning that the common type of a char and immutable(char) is int. It should be char. I'm reassigning this to Walter.
Comment #3 by rayerd.wiz — 2010-08-06T05:50:36Z
(In reply to comment #2) > This is a bug in the compiler. Consider: > > import std.stdio; > void main() > { > auto x = true ? ("a".dup)[0] : "b"[0]; > writeln(typeof(x).stringof); > } > > This program prints int, meaning that the common type of a char and > immutable(char) is int. It should be char. > > I'm reassigning this to Walter. As Andrei said, This issue was not a bug of phobos, but this is a bug of conditional operator. Is it difficult to fix?
Comment #4 by rayerd.wiz — 2011-02-27T07:45:37Z
*** This issue has been marked as a duplicate of issue 5659 ***