[Issue 5286] New: To avoid a problem with Template syntax

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 28 15:15:32 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5286

           Summary: To avoid a problem with Template syntax
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-11-28 15:14:06 PST ---
D has removed some cases of bug-prone C syntax, like:

int main() {
    int* ptr1, ptr2;
    return 0;
}


But D must avoid introducing new ones. D2 has introduced a handy shortcut to
define templates, but this shortcut must not cause ambiguity for the eyes of
the programmer that reads the code (I don't care if the syntax is perfectly
defined for the D compiler, here I am talking about human users and their
fallible nature. Because the same was true for some C syntax too, that is well
defined for the compiler).

So to avoid troubles this code raises a syntax error, this is good:

struct Foo(T) {}
Foo!Foo!int y;
void main() {}

test.d(2): multiple ! arguments are not allowed


But this D2 code too may be ambiguous for the person that reads it:

struct Foo(T) {}
Foo!int* x;
static assert(!is(typeof(x) == Foo!(int*)));
static assert(is(typeof(x) == Foo!(int)*));
void main() {}


In similar situations I'd like D to require parentheses (so "Foo!int* x;"
becomes a syntax error), so the programmer must write:
Foo!(int*)
or:
Foo!(int)*

And this possible source of confusion for the person that reads the code is
avoided.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list