Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 9570 - Wrong foreach index implicit conversion error #3567

Merged
merged 1 commit into from Jun 15, 2014

Conversation

lionello
Copy link
Contributor

Initial attempt to fix bug 9570.

Added a IntRange* to VarDeclaration which tracks the range for variables for which the range is known, in this case foreach over range, array and sarray. This range will only be used when the iterator is declared const or immutable.

Added a simple test case, based on bug report. This PR is also needed to fix bug 259 (prevent false positives.)

range = *vd->range;
}
else
visit((Expression*)e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expression *

@WalterBright
Copy link
Member

@@ -2605,6 +2617,12 @@ Statement *ForeachRangeStatement::semantic(Scope *sc)
ExpInitializer *ie = new ExpInitializer(loc, (op == TOKforeach) ? lwr : upr);
key = new VarDeclaration(loc, upr->type->mutableOf(), Lexer::uniqueId("__key"), ie);
key->storage_class |= STCtemp;
SignExtendedNumber l = getIntRange(lwr).imin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use variables named 'l', as they are too easily confused with '1'.

@lionello
Copy link
Contributor Author

lionello commented Jun 3, 2014

@yebblies @WalterBright all is well :)

WalterBright added a commit that referenced this pull request Jun 15, 2014
Issue 9570 - Wrong foreach index implicit conversion error
@WalterBright WalterBright merged commit 34d9708 into dlang:master Jun 15, 2014
@lionello lionello deleted the bug9570 branch June 16, 2014 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants