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

Improve failing foreach reporting for struct and class aggregates #3606

Merged
merged 1 commit into from
Aug 25, 2014

Conversation

nordlow
Copy link
Contributor

@nordlow nordlow commented May 30, 2014

Should I, similarly for enums, add tip for __traits(members)?

@nordlow nordlow changed the title Add tip for when to use tupleof for struct and classes Add tupleof tip for struct and classes May 30, 2014
@nordlow nordlow changed the title Add tupleof tip for struct and classes Add tupleof tip for structs and classes May 30, 2014
@ghost
Copy link

ghost commented May 30, 2014

I don't think this is right. If you want to use opApply or a range .tupleof is likely not what you wanted.

@nordlow
Copy link
Contributor Author

nordlow commented May 30, 2014

I don't understand what you mean with opApply or range.

What role does opApply play here and what has ranges to do with classes or structs?

Could you elaborate a bit, please?

@mihails-strasuns
Copy link

If someone has tried to do foreach over struct it is much more likely that this person expected opApply to be defined, not iterate over all fields. Thus new error message is misleading.

@nordlow
Copy link
Contributor Author

nordlow commented May 30, 2014

Aha, wasn't aware of that.

What about suggesting (in error message) both my current proposal together with an alternative to add an opApply() definition?

@nordlow
Copy link
Contributor Author

nordlow commented Jun 1, 2014

I updated the reporting to provide hints for implementing opApply aswell.

Could somebody explain why this is failing? I've not been able to run the make test on dmd because of problem mention at the top of this discussion.

@nordlow nordlow changed the title Add tupleof tip for structs and classes Improve failing foreach reporting for struct and class aggregates Jun 1, 2014
@dnadlinger
Copy link
Member

The error message should still start with, well, an actual error message. Right now, it only consists of suggested fixes. Maybe something like invalid foreach aggregate %s (define opApply member or use .tupleof to iterate over fields) would work better (disregard the actual wording, it's only a rough idea).

Still not sure about featuring tupleof so prominently, though, as the others mentioned.

@yebblies
Copy link
Member

yebblies commented Jun 7, 2014

At a guess, it could be failing because there is a code path that returns new ErrorStatement without actually generating/printing an error.

I don't think slapping .tupleof onto an aggregate is very often the solution when you see this error.

@9rnsr
Copy link
Contributor

9rnsr commented Jun 7, 2014

Too verbose diagnostic message is rather harmful.

How about?

const char *s = "";
if (aggr->type && isAggregate(aggr->type))
    s = " (define opApply, range primitives,  or use .tupleof)";
error("invalid foreach aggregate %s%s", aggr->toChars(), s);

else if (aggr->type->ty == Tclass)
{
error("either suffix foreach aggregate %s with .tupleof or implement class %s's member int opApply(int delegate(ref Type [, ...]) dg)", aggr->toChars(), aggr->type->toChars());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In else branch, no error is reported but this ForeachStatement::semantic will return ErrorStatement. It is the reason of Auto-tester breaking.

@nordlow
Copy link
Contributor Author

nordlow commented Jun 7, 2014

Great! I'll look into it!

@nordlow nordlow force-pushed the tupleof-tip branch 2 times, most recently from 16989bf to dba9f2e Compare August 24, 2014 11:45
@nordlow
Copy link
Contributor Author

nordlow commented Aug 24, 2014

I used comma as separator as this is more in line with other messages such as the one introduced in

http://dlang.org/changelog.html#warn_unused_retval

I believe this is ready for merge.

@nordlow
Copy link
Contributor Author

nordlow commented Aug 25, 2014

This passed on all targets yesterday. Can somebody explain why it doesn't on Win64 anymore?

@yebblies
Copy link
Member

This passed on all targets yesterday. Can somebody explain why it doesn't on Win64 anymore?

http://en.wikipedia.org/wiki/Lunar_phase

@nordlow
Copy link
Contributor Author

nordlow commented Aug 25, 2014

:)

All is well again. BTW: Should I squash commits?

@yebblies
Copy link
Member

Yes.

Alternative warning

Better message

Use comma instead of parenthesis for extra tip
@nordlow
Copy link
Contributor Author

nordlow commented Aug 25, 2014

Squash done.

@9rnsr
Copy link
Contributor

9rnsr commented Aug 25, 2014

LGTM.

@9rnsr
Copy link
Contributor

9rnsr commented Aug 25, 2014

Auto-merge toggled on

@nordlow
Copy link
Contributor Author

nordlow commented Aug 25, 2014

Thanks.

9rnsr added a commit that referenced this pull request Aug 25, 2014
Improve failing foreach reporting for struct and class aggregates
@9rnsr 9rnsr merged commit 2f1d27c into dlang:master Aug 25, 2014
@nordlow nordlow deleted the tupleof-tip branch October 19, 2021 19:43
ibuclaw pushed a commit to ibuclaw/dmd that referenced this pull request Jul 10, 2022
Remove useless conditional assignment of DISABLED_TESTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants