Bug 2337 – Can't set .length property in CTF.

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2008-09-05T18:10:00Z
Last change time
2014-03-01T00:36:37Z
Assigned to
nobody
Creator
aziz.koeksal

Comments

Comment #0 by aziz.koeksal — 2008-09-05T18:10:34Z
The page for functions says that some "properties can be executed at compile time", and it lists .length as one of those properties. Unfortunately it can only be accessed by reading it, but assigning a value to it is not possible. For example: char[] ctf() { // Create a table: char[][] table = []; // table.length = 250; // No simple enlargement. // Use ugly workaround: for (uint i; i < 250; i++) table ~= []; char[] code = ""; // Create code from table. return code; } pragma(msg, ctf()); I think this shouldn't be too difficult to implement.
Comment #1 by yebblies — 2011-06-10T04:39:59Z
This works in dmd1.068 (and dmd2.053).