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
Fix 23216 - Better error message for foreach_reverse without Bidirectional Range #14254
Conversation
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14254" |
df26c24
to
589145a
Compare
It seems that struct Range
{
bool empty = true;
int front = 0;
void popFront() { }
int back = 1;
}
void main()
{
Range r;
foreach_reverse (word; r) { }
} issue: "Error: no property whereas, this code: struct Range
{
bool empty = true;
int front = 0;
void popFront() { }
int popBack = 1;
}
void main()
{
Range r;
foreach_reverse (word; r) { }
} issues: "test.d(12): Error: invalid Although it's a minor concern, I think that this inconsistency should be fixed. |
589145a
to
cd70e4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
It doesn't check for the correct function signatures either, it's only guessing whether it's intended to use the range interface instead of |
" (implementing `front` and `popFront`), aggregates implementing" ~ | ||
" `opApply`, or the result of an aggregate's `.tupleof` property"); | ||
fs.loc.errorSupplemental("https://dlang.org/phobos/std_range_primitives.html#isInputRange"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the 2 paths. You can combine them and use a ternary condition to select the appropriate string between foreach
and foreach_reverse
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @dkorpel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of a ternary here? I think it's more readable like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fewer lines of code, consistency with how this sort of case is treated in the rest of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the minimum, the error supplemental should not be duplicated. Nvm.
No description provided.