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

Fix Issue 19181: always error when an UFCS or opDispatch call has syntactically invalid arguments #8584

Conversation

FeepingCreature
Copy link
Contributor

@FeepingCreature FeepingCreature commented Aug 20, 2018

Repro:

$ dmd test.d
---
module test;

struct S {
    void opDispatch(string name, T)(T arg) { }
}

void main() {
    S s;
    s.foo(LanguageError);
}

Before:
test.d(9): Error: no property foo for type S

After:
test.d(9): Error: undefined identifier LanguageError

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @FeepingCreature! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
19181 normal Semantic errors in opDispatch argument lead to "no property X"

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#8584"

@FeepingCreature
Copy link
Contributor Author

Holy hell, that's the fastest approval I have ever gotten on Github, let alone DMD.

Copy link
Contributor

@jacob-carlborg jacob-carlborg left a comment

Choose a reason for hiding this comment

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

Needs to have a test.

@JinShil
Copy link
Contributor

JinShil commented Aug 20, 2018

Doesn't this need a test case to prevent a regression.

@jacob-carlborg
Copy link
Contributor

Holy hell, that's the fastest approval I have ever gotten on Github, let alone DMD.

Sorry, I had to change my mind.

@jacob-carlborg
Copy link
Contributor

Doesn't this need a test case to prevent a regression.

Yes, I changed my mind and requested changes.

@FeepingCreature
Copy link
Contributor Author

FeepingCreature commented Aug 20, 2018

The original behavior is not strictly speaking wrong, it's just highly misleading. opDispatch does fail to match since the call fails to compile - it just fails to compile due to a call-site error. That said, I'm not sure how you test for a specific error message.

edit: The test failure is in master unchanged. God damnit. Why do we even have tests.

@JinShil
Copy link
Contributor

JinShil commented Aug 20, 2018

That said, I'm not sure how you test for a specific error message.

See examples in the test/fail_compilation directory for examples. Also see TEST_OUTPUT described in the Readme at https://github.com/dlang/dmd/tree/master/test

@FeepingCreature FeepingCreature force-pushed the fix/Issue-19181-error-on-invalid-arguments-in-ufcs-opDispatch branch from 126b2df to 0534fee Compare August 20, 2018 06:58
@FeepingCreature
Copy link
Contributor Author

FeepingCreature commented Aug 20, 2018

Thanks. Test added.

fail_compilation/fail19181.d(13): Error: undefined identifier LanguageError
---
*/
struct S {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please follow the standard D style, curly braces on their own lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@FeepingCreature FeepingCreature force-pushed the fix/Issue-19181-error-on-invalid-arguments-in-ufcs-opDispatch branch from 0534fee to 56ea52d Compare August 20, 2018 07:02
/*
TEST_OUTPUT:
---
fail_compilation/fail19181.d(15): Error: undefined identifier LanguageError
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the tests suite will probably fail because LanguageError needs to be surrounded with tick marks. We'll find out soon enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the other tests have that too, I've just gone ahead and added it. Can't hurt.

@FeepingCreature FeepingCreature force-pushed the fix/Issue-19181-error-on-invalid-arguments-in-ufcs-opDispatch branch from 56ea52d to 52ee235 Compare August 20, 2018 07:05
@jacob-carlborg
Copy link
Contributor

jacob-carlborg commented Aug 20, 2018

Back to approved, still less than 20 minutes 😃.

@FeepingCreature
Copy link
Contributor Author

Still the fastest, I believe!

@FeepingCreature
Copy link
Contributor Author

Again, that is not an error in my change.

@JinShil
Copy link
Contributor

JinShil commented Aug 20, 2018

Again, that is not an error in my change.

Are you sure? Run the test suite locally with make -C test -f Makefile. Or to run just the failing test use rdmd test/run.d test/fail_compilation/ice14929.d.

@FeepingCreature
Copy link
Contributor Author

FeepingCreature commented Aug 20, 2018

Are you sure?

Yes I am, given that it happens on master. 😄

edit: I AM AN IDIOT who doesn't understand how fail tests work. Thanks! This is definitely at least a change from my code.

edit: Hah! The test was wrong.

edit: Specifically, the body of the typeof was semantically invalid, which due to the change errored before the add() internal error hit, which made the typeof() evaluate to false, as it should.

@FeepingCreature FeepingCreature force-pushed the fix/Issue-19181-error-on-invalid-arguments-in-ufcs-opDispatch branch from 52ee235 to 4ea3485 Compare August 20, 2018 09:35
@@ -75,7 +75,7 @@ template isComponentStorage(CS, C)
{
CS cs = CS.init;
ulong eid;
cs.add(eid, c);
cs.add(eid, C.init);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change necessary?

Copy link
Contributor Author

@FeepingCreature FeepingCreature Aug 20, 2018

Choose a reason for hiding this comment

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

Fun reason: Previously, DMD would try to semantically evaluate cs.add before figuring out what if anything c is, hit the !in instantiation error, and bail with the TEST_OUTPUT message. WIth this PR's change, it verifies the arguments to cs.add() first and immediately notices that there is no such variable as c, causing the typeof to fail and, as is typeof's wont, silently return false. Since I can only presume that the fact that c doesn't exist is not actually the point of this test, since there's no comment and it's unrelated to the error message, I just went ahead and made it semantically valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes, of course. I was reading the corrected code and tried to figure out what was wrong with it 😃.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a bit weird and inconsistent that typeof errors out if only the error that happens in typeof is in a different template.

But that's neither what this bug nor the testcase's bug is about, so ... 🤷‍♂️

@wilzbach
Copy link
Member

Or to run just the failing test use rdmd test/run.d test/fail_compilation/ice14929.d.

FYI: for the lazy people like me: ./test/run.d fail_compilation/ice14929.d and a few other combinations work too.

@dlang-bot dlang-bot merged commit c2317ad into dlang:master Aug 20, 2018
MartinNowak pushed a commit to FeepingCreature/dmd that referenced this pull request Aug 29, 2018
…ror-on-invalid-arguments-in-ufcs-opDispatch

Fix Issue 19181: always error when an UFCS or opDispatch call has syntactically invalid arguments
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
@MoonlightSentinel
Copy link
Contributor

This introduced a regression: https://issues.dlang.org/show_bug.cgi?id=20488

@FeepingCreature FeepingCreature deleted the fix/Issue-19181-error-on-invalid-arguments-in-ufcs-opDispatch branch January 15, 2020 09:13
@FeepingCreature
Copy link
Contributor Author

(Regression fixed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants