Bug 2601 – Extraneous cast introduced in member access

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2009-01-21T11:50:00Z
Last change time
2014-04-18T09:12:04Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2009-01-21T11:50:18Z
I could probably simplify this a bit more, but it's short enough: import std.functional; void next(T)(ref T[] a) { assert(a.length); a = a[1 .. $]; } struct MapRange(alias funAlias, Range) { Range _input; void next() { _input.next; } } template map(fun...) { alias mapImpl!(fun).result map; } template mapImpl(alias fun) { MapRange!(fun, Range) result(Range)(Range input) { return typeof(return)(input); } } unittest { auto x = map!("2 * a")([1, 2, 3, 4, 5]); //auto y = mapImpl!(fun).result!("2 * a")([1, 2, 3, 4, 5]); } The code fails to compile with: Error: cast(int[])this._input is not an lvalue As a bonus, uncommenting the last (albeit incorrect) line in unittest crashes dmd.
Comment #1 by clugdbug — 2010-01-15T04:37:28Z
The segfault was fixed long ago. Reduced test case also fails on D1. I'm not certain it's a bug, though. -------- void next(ref int[] a) { a[0] = 0; } void bug2601() { int[3] b; next(b); } bug.d(5): Error: cast(int[])b is not an lvalue
Comment #2 by yebblies — 2011-06-12T21:52:41Z
I think array literals have become dynamic since then, so the case in comment 1 works. The case in comment 2 does not appear to be a bug, casting a static array to a dynamic array cannot result in an lvalue.