[Issue 13574] New: incorrect code for assignment to dollar in slice expression
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Oct 4 06:11:58 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13574
Issue ID: 13574
Summary: incorrect code for assignment to dollar in slice
expression
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: code at dawg.eu
cat > bug.d << CODE
extern (C) int printf(const char*, ...);
struct Foo
{
void opSlice(size_t a, size_t b) { printf("%zu %zu\n", a, b); }
alias opDollar = length;
size_t length;
}
void main()
{
Foo foo;
foo[0 .. foo.length = 1];
assert(foo.length == 1);
foo[0 .. $ = 2]; // assigns to the temporary dollar variable
assert(foo.length == 2);
}
CODE
dmd -run bug
----
AFAIK we're currently caching the result of opDollar to avoid reevaluating of
side-effects. If that should remain the case the opDollar tmp variable needs to
be const.
Alternatively we could also allow side-effects in opDollar (requires strict
left to right evaluation) and not cache the value. This might be a bad choice
when length is costly to compute.
--
More information about the Digitalmars-d-bugs
mailing list