Patch against dmd r687, CTFE on tuple slice boundaries
text/plain
1662
Comments
Comment #0 by rsinfu — 2010-09-25T21:25:29Z
Type tuples can't be sliced with boundaries that involve CTFE-able function call(s). The following valid code doesn't compile (both D1 & D2):
--------------------
template T(_...) { alias _ T; }
size_t mid(size_t n) { return n/2; }
alias T!(int, int, int)[0 .. mid($)] A;
// Error: Integer constant expression expected instead of mid(3u)
--------------------
Patch against dmd r687, makes it sure that TypeSlice boundaries get CTFE'd.
--- src/mtype.c
+++ src/mtype.c
@@ -7787,11 +7787,11 @@ Type *TypeSlice::semantic(Loc loc, Scope *sc)
TypeTuple *tt = (TypeTuple *)tbn;
lwr = semanticLength(sc, tbn, lwr);
- lwr = lwr->optimize(WANTvalue);
+ lwr = lwr->optimize(WANTvalue | WANTinterpret);
uinteger_t i1 = lwr->toUInteger();
upr = semanticLength(sc, tbn, upr);
- upr = upr->optimize(WANTvalue);
+ upr = upr->optimize(WANTvalue | WANTinterpret);
uinteger_t i2 = upr->toUInteger();
if (!(i1 <= i2 && i2 <= tt->arguments->dim))
Comment #1 by rsinfu — 2010-09-25T22:11:04Z
Created attachment 776
Patch against dmd r687, CTFE on tuple slice boundaries
The attached patch obsoletes the patch in comment #0. The new one applies the same fix to other relevant parts, and fixes following additional cases:
template T(_...) { alias _ T; }
size_t mid(size_t n) { return n/2; }
alias T!(int, int)[0 .. mid($)] A; // A
alias T!(1, 2, 3)[0 .. mid($)] B; // B
void main()
{
T!(int, int, int) values;
auto slice = values[0 .. mid($)]; // C
}