www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15368] New: Improve error message for "auto" keyword inside


          Issue ID: 15368
           Summary: Improve error message for "auto" keyword inside
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ajidala gmail.com

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

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/cwlvurvwdnqeourtvbvi forum.dlang.org 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. --
Nov 20 2015