www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - foreach changes in 1.0 - looping through struct array's unexpected

I came across a strange behaviour in dmd1.0

We are writing a syncml server, part of which uses wbxml, and has a big
set of static structs arrays defining the wbxml elements:

This code worked perfectly before 1.0

foreach(mt;mainTable) {
	writefln("test %s", mt.publicID.xmlPublicID);
	if (mt.publicID.xmlPublicID == publicIdStr) {
		return mt;

mainTable looks a bit like this:

struct WBXMLLangEntry
		int               langID;
		WBXMLPublicIDEntry    publicID;
		WBXMLTagEntry[]        tagTable;
		WBXMLNameSpaceEntry[]   nsTable;
		WBXMLAttrEntry[]        attrTable;
		WBXMLAttrValueEntry[]   attrValueTable;
		WBXMLExtValueEntry[]    extValueTable;
const WBXMLLangEntry mainTable[] = [
			{ WBXML_LANG_WML10,             sv_wml10_public_id,
sv_wml10_tag_table,             null,
sv_wml10_attr_table,        sv_wml10_attr_value_table,      null },

Where all those WBXML items are structs as well.

using dmd pre1.0 the code would look up a string in those tables, and
return the table entry. - In 1.0, it would loop through all the entries,
but the string was blank.

The workaround for 1.0 appears to be:
foreach(i,mt;mainTable) {
	writefln("test %s", mainTable[i].publicID.xmlPublicID);
	if (mainTable[i].publicID.xmlPublicID == publicIdStr) {
		return mainTable[i];

(eg. not trusting the foreach struct result., and using the index.)

Oddly enough just looping through and printing (without the testing
appears to print all the items)

Any ideas why this may have changed?

Jan 11 2007