Hello,<br><br>This is Part 1 of the language spec documentation review which I&#39;m doing. So far I&#39;ve covered maybe 1/3rd of the links in the spec docs.<br><br>I am going to make a bug report for this, but I was thinking it might be a good idea if someone could review my findings first (Let me know if you want the bug report right away and I will do one asap.). Some of these could likely be my own mistakes, or my misinterpretation of the docs.<br>
<br>The first column is the link to the docs section, the next indentation is the relevant subsection title (you&#39;ll have to do a CTRL+F to find the code examples, there&#39;s not that many &#39;href&#39; anchors in the html docs, sorry), and the next indent are the errors/comments. When I say &quot;example&quot; in the text, I mean the relevant code example from the docs.<br>
<br>All of these examples were tested with DMD 2.046 on XP-32bit, unfortunately I had trouble setting up DSSS in Ubuntu (and I&#39;m too lazy to make makefiles) so I didn&#39;t test on that platform.<br><br>So, here&#39;s the copypasta:<br>
<br><a href="http://www.digitalmars.com/d/2.0/module.html">http://www.digitalmars.com/d/2.0/module.html</a><br>    &quot;Mixin Declaration&quot;<br>        This should be moved to the &quot;Declarations&quot; section.<br>
        <br>        <br><a href="http://www.digitalmars.com/d/2.0/declaration.html">http://www.digitalmars.com/d/2.0/declaration.html</a><br>    &quot;Aliases cannot be used for expressions&quot;<br>        The code example compiles even though it says it is illegal.<br>
<br><br><a href="http://www.digitalmars.com/d/2.0/type.html">http://www.digitalmars.com/d/2.0/type.html</a><br>    &quot;Implicit Conversions&quot;<br>        Last line in the example:<br>            f = E;<br>        E is undefined, the line should be:<br>
            f = Foo.E;<br>    <br>    &quot;Delegates&quot;<br>        In the example, assigning the address of a function to a<br>        function pointer gives a compilation error:<br>            Error: cannot implicitly convert expression <br>
            (&amp;func) of type int delegate(int) to int function(int)<br><br>        <br><a href="http://www.digitalmars.com/d/2.0/property.html">http://www.digitalmars.com/d/2.0/property.html</a><br>    &quot;.init Property&quot;<br>
        &quot;Foo.b.init&quot; is 0, not 7.<br><br>    &quot;.stringof Property&quot;<br>        Example contains two lines refering to &quot;test.Foo&quot;,<br>        but &quot;test&quot; isn&#39;t declared anywhere. <br>
        The compiler output is different too.<br>        <br>        The lines should be replaced with:<br>            writefln((1+2).stringof);       // &quot;1 + 2&quot;<br>            writefln(Foo.stringof);         // &quot;Foo&quot;<br>
            writefln(int.stringof);         // &quot;int&quot;<br>            writefln((int*[5][]).stringof); // &quot;int*[5u][]&quot;<br>            writefln(Enum.RED.stringof);    // &quot;Enum<br>            writefln((5).stringof);         // &quot;5&quot;<br>
<br>    &quot;.sizeof Property&quot;<br>        Compilation error:<br>            sizeof_test.d(14): Error: &#39;this&#39; is only defined in non-static<br>            member functions, not test<br>            <br>        Maybe a compiler bug? If &quot;int x = S.a.sizeof&quot; is put outside the<br>
        test() function, it will compile.<br><br><br><a href="http://www.digitalmars.com/d/2.0/attribute.html">http://www.digitalmars.com/d/2.0/attribute.html</a><br>    &quot;immutable Attribute&quot;<br>    &quot;__gshared Attribute&quot;<br>
    &quot;shared Attribute&quot;<br>    &quot;inout Attribute&quot;<br>        <br>    There is missing documentation for these.<br><br>        <br><a href="http://www.digitalmars.com/d/2.0/expression.html">http://www.digitalmars.com/d/2.0/expression.html</a>        <br>
    &quot;A CatExpression concatenates arrays, producing a dynmaic&quot;<br>        typo: dynmaic &gt; dynamic.<br>    <br>    &quot;Array Literals&quot;<br>        Third example from the title:<br>            writeln(ct);  // writes [1 1]<br>
            writeln(rt);  // writes [257]<br>    <br>        The output is instead:<br>            1 1<br>            1 0 1 0<br>    <br>    &quot;is ( Type Identifier )&quot;<br>        Replace any &#39;writefln&#39; with &#39;writeln&#39; (missing format specifiers).<br>
<br>    &quot;is ( Type Identifier : TypeSpecialization )&quot;<br>        Replace any &#39;writefln&#39; with &#39;writeln&#39;.<br><br>    &quot;is ( Type Identifier == TypeSpecialization , TemplateParameterList )&quot;<br>
        Replace any &#39;writefln&#39; with &#39;writeln&#39;.<br><br><a href="http://www.digitalmars.com/d/2.0/statement.html">http://www.digitalmars.com/d/2.0/statement.html</a><br>    &quot;Labeled Statements&quot;<br>
        It states:<br>            &#39;&#39;Labels are in a name space independent of declarations, variables,<br>            types, etc. Even so, labels *cannot* have the same name as local<br>            declarations.&#39;&#39;<br>
<br>        However this custom example compiles:<br><br>        void func() {<br>            int t;<br>            t: {<br>                int xyz;<br>            }<br>        }<br><br>        So does this one:<br>        <br>
        void func() {<br>            int t;<br>            xyz: {<br>                int xyz;<br>            }<br>        }<br>        <br>        Perhaps this was meant to state:<br>            &quot;Declarations *inside* labels cannot have the same name<br>
            as local declarations&quot; ?<br>        <br>    &quot;foreach_reverse&quot;<br>        IIRC this will be replaced with retro sometime soon? foreach_reverse<br>        still works though.<br><br>    &quot;Foreach over Arrays of Characters&quot;<br>
        First example, these lines:<br>            char[] a = &quot;\xE2\x89\xA0&quot;;    // \u2260 encoded as 3 UTF-8 bytes<br>            dchar[] b = &quot;\u2260&quot;;            // prints &#39;a[] = 2260&#39;<br>            <br>
        Should be replaced with:<br>            char[] a = &quot;\xE2\x89\xA0&quot;.dup;    // \u2260 encoded as 3 UTF-8 bytes<br>            dchar[] b = &quot;\u2260&quot;d.dup;          // prints &#39;a[] = 2260&#39;<br>
<br>    &quot;Foreach over Associative Arrays&quot;<br>        The first example code gives these compiler errors:<br>            foreach_test.d(38): Error: function<br>            object.AssociativeArray!(const(char)[],double).AssociativeArray.opApply<br>
            (scope int delegate(ref const(char)[], ref double) dg) is not callable<br>            using argument types (int delegate(ref double __applyArg0, <br>            ref char[] __applyArg1))<br><br>            foreach_test.d(38): Error: cannot implicitly convert expression<br>
            (__foreachbody524) of type int delegate(ref double __applyArg0, <br>            ref char[] __applyArg1) to int delegate(ref double)<br><br>        Changing the foreach statement like so seems to work:<br>            double[char[]] a;<br>
<br>            foreach (const (char)[] s, ref double d; a)<br>            {<br>                writefln(&quot;a[&#39;%s&#39;] = %g&quot;, s, d);<br>            } <br>    <br>    &quot;Foreach over Structs and Classes with opApply&quot;<br>
        The sentence:<br>        <br>        &quot;The body of the apply function iterates over the elements it aggregates&quot;<br>        Has a typo, change &quot;it aggregates&quot; to &quot;in aggregates&quot;.<br>    <br>
    &quot;Foreach over Tuples&quot;<br>        In the first example, replace any &#39;writefln&#39; with &#39;writeln&#39;.<br>        <br>        In foreach over arrays it states:<br>            &#39;&#39;The index must be of int, uint or size_t type&#39;&#39;<br>
        <br>        In foreach over tuples it states:<br>            &#39;&#39;The index must be of int or uint type.&#39;&#39;<br>            <br>        Is there a reason why one is allowed to be of size_t type,<br>        and the other is not?<br>
<br>    &quot;Foreach Restrictions&quot;<br>        The example:<br>            int[] a;<br>            int[] b;<br>            foreach (int i; a)<br>            {<br>                a = null;                    // error<br>
                a.length = a.length + 10;    // error<br>                a = b;                        // error<br>            }<br>            a = null;                        // ok<br><br>        None of these give compilation errors or warnings.<br>
        Adding memmory allocation statements for a and b before<br>        entering the loop does not cause any compiler errors, and<br>        no runtime exceptions are raised.<br>        <br>    &quot;Switch Statement&quot;<br>
        The sentence:<br>            &#39;&#39;If none of the case expressions match, and there is not a default<br>            statement, a [link:std.switcherr.SwitchError] is thrown.&#39;&#39;<br>            <br>        The link redirects to a 404 page. <br>
        &quot;std.switcherr.SwitchError&quot; should be replaced <br>        with &quot;core.exception.SwitchError&quot;.<br><br>    &quot;Final Switch Statement&quot;<br>        What is this used for? CTFE maybe? I&#39;m curious. :)<br>
<br>    &quot;Scope Guard Statement&quot;<br>        In all of the examples under this section<br>        &#39;writefln&#39; should be replaced with &#39;writeln&#39;,<br>        and &#39;writef&#39; with &#39;write&#39;.<br>
<br>    &quot;Mixin Statement&quot;<br>        Replace &#39;writefln&#39; with &#39;writeln&#39; in the mixin string.<br>        <br>        The line:<br>            char[] t = &quot;y = 3;&quot;;<br>        Replace it with:<br>
            char[] t = &quot;y = 3;&quot;.dup;<br>    <br>        Now only the documentation-relevant errors are shown when compiling.<br>    <br>    &quot;Foreach Range Statement&quot;<br>        This should be moved up, close to where the other foreach definitions are.<br>
        <br>        In the example code:<br>            Replace &#39;writefln&#39; with &#39;writeln&#39;, and &#39;writef&#39; with &#39;write&#39;.<br><br><br><a href="http://www.digitalmars.com/d/2.0/arrays.html">http://www.digitalmars.com/d/2.0/arrays.html</a><br>
    &quot;Usage&quot;<br>        The lines:<br>            p = s;        // p points to the first element of the array s.<br>            p = a;        // p points to the first element of the array a.<br>        <br>        Give compiler errors:<br>
            Error: cannot implicitly convert expression (s) of<br>            type int[3u] to int*<br>            Error: cannot implicitly convert expression (a) of<br>            type int[] to int*<br>        <br>        Casts work:<br>
            p = cast(int*) s;<br>            p = cast(int*) a;<br>            <br>        But is that a good workaround? Don&#39;t ask me.. :p<br>    <br>    &quot;Array Properties&quot;<br>        In the first example there are missing declarations. <br>
        Could add these before the first line:<br>            int* p;<br>            int[3] s;<br>            int[] a;<br><br>    &quot;Setting Dynamic Array Length&quot;<br>        From the comments in the first example, it states:<br>
            &#39;&#39;// always resized in place because it is sliced<br>              // from a[] which has enough memory for 15 chars&#39;&#39;<br>        <br>        But in this shorter example:<br>            char[] a = new char[50];<br>
            char[] b = a[0..10];  <br><br>            b.length = 11;                <br>            a[3] = &#39;z&#39;;                <br>            writeln(b); // writes 11 default characters<br><br>        from my tests, resizing b to any bigger length always creates a copy, <br>
        regardless of how big the length of a is.<br>        <br>        Resizing to a smaller length (e.g. 8) will keep the reference,<br>        and b[3] will still refer to a[3] in the example.<br>        <br>        Has the resizing behavior changed recently, or is that comment inaccurate?<br>
<br>    &quot;Functions as Array Properties&quot;<br>        From this example code:<br>            int[] array;<br>            void foo(int[] a, int x);<br><br>            foo(array, 3);<br>            array.foo(3);    // means the same thing<br>
<br>        The last line does not compile, even when foo() is fully defined:<br>            Error: undefined identifier module main.foo<br><br>    &quot;Array Bounds Checking&quot;<br>        In the example code, &quot;ArrayBoundsError&quot; should be replaced <br>
        with &quot;RangeError&quot;.<br>    <br>    &quot;Static Initialization of Static Arrays&quot;<br>        For the example code:<br>            enum Color { red, blue, green };<br>            int value[Color.max + 1] = [ Color.blue:6, Color.green:2, Color.red:5 ];<br>
<br>        The documentation states:<br>            &#39;&#39;These arrays are static when they appear in global scope. <br>            Otherwise, they need to be marked with const or static <br>            storage classes to make them static arrays.&#39;&#39;<br>
            <br>        In non-global scope, the array has to be marked with static in order<br>        to compile. const alone is not compilable. At least not in my case.<br><br>    &quot;Special Array Types&quot;<br>        The 6th example from the title:<br>
            cast(wchar [])&quot;abc&quot;    // this is an array of wchar characters<br>            &quot;abc&quot;w                // so is this<br>        <br>        It should probably be noted that the first line returns a copy of the <br>
        string with type wchar[], while the second line returns a copy(?) <br>        of the string with type immutable(wchar)[]. But correct me if I&#39;m wrong with this one.<br><br>        The next example has this line:<br>
            w = \r[0];        // w is assigned the carriage return wchar character<br>        Needs to be replaced with:<br>            w = &quot;\r&quot;[0];    // w is assigned the carriage return wchar character<br><br>
    &quot;Associative Arrays&quot;<br>        Accessing a nonexistent key for an AA throws the RangeError exception.<br>        Perhaps a different exception should be created for AA&#39;s, such as:<br>            core.exception.KeyNotInAssocArray<br>
        ?<br>        <br>    &quot;Using Classes as the KeyType&quot;<br>        In the example code, any &quot;f&quot; in a declaration/expression needs to be<br>        replaced with &quot;foo&quot;.<br><br>    &quot;Using Structs or Unions as the KeyType&quot;<br>
        The line in the example:<br>            foreach (char c; s)<br>        Should be:<br>            foreach (char c; str)<br><br>// end<br><br>