[Issue 15368] New: Improve error message for "auto" keyword inside "foreach"
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Fri Nov 20 12:12:51 PST 2015
    
    
  
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: nobody at puremagic.com
          Reporter: ajidala at gmail.com
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/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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list