foreach problem

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Jan 5 15:03:48 PST 2007


Dejan Lekic wrote:
> Mr/Mrs BCS,
> here is the part of documentation i maybe did not understand well:
> ----------------- snip ------------------
> ForeachStatement:
>     Foreach (ForeachTypeList; Aggregate) ScopeStatement
> 
> Foreach:
>     foreach
>     foreach_reverse
> 
> ForeachTypeList:
>     ForeachType
>     ForeachType , ForeachTypeList
> 
> ForeachType:
>     inout Type Identifier
>     Type Identifier
>     inout Identifier
>     Identifier
> ----------------- snip ------------------
> 
> If I understand this correctly, than simple code like the one in foreach_bug.d
> should work because 'arg' is clearly an 'Identifier' from the 'ForeachType' rule
> above.

I'm pretty sure that if you look only at the syntax definition, the 
following (full) program is also valid:

-----
void something(X Y)	         // X undefined
{
	blaat() + "yeah";        // blaat undefined
	Z = 1.234;               // Z undefined
	int b = [1, "foo", .2];  // init value is invalid array
                                  // literal, and certainly not an int
}
-----

It's only when you try to make sense of it that you realize that even 
though it's syntactically correct, it's full of semantic errors.
In fact, I just ran that file through 'dmd -v' and it parses fine. The 
semantic pass is where it errors out. Same as your example, though yours 
doesn't error out until the third semantic pass instead of giving up in 
the first one.


More information about the Digitalmars-d-bugs mailing list