https://issues.dlang.org/show_bug.cgi?id=15368

          Issue ID: 15368
           Summary: Improve error message for "auto" keyword inside
                    "foreach"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

Users may attempt to do type inference in foreach statements in the following
way: 

foreach (auto e; foo) { }

However, this causes the following compilation error:
>Error: basic type expected, not auto

This can be fairly misleading as an inexperienced programmer may assume that
type inference is not possible inside foreach statements, as the compiler says
it expects a basic type (when it syntactically actually doesn't).

As per http://forum.dlang.org/post/[email protected] I
suggest adding a special case if the unexpected token inside a foreach
statement's declaration is "auto", pointing out that "auto" is neither needed
nor allowed in this context to get type inference.

--

Reply via email to