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 2450 - Error using operators from named template mixin #10406

Merged
merged 1 commit into from Sep 14, 2019

Conversation

RazvanN7
Copy link
Contributor

template Event() {
	void opCall() { }
	void opAddAssign(int i) { }
}
class Button {
	mixin Event clicked;
	void func() {
		clicked.opCall(); // works
		this.clicked();   // works   => should not work, fixed by this patch

		// Error: function expected before (), not mixin Event!() clicked; of type void
		clicked();
		// Error: mixin 'Event!()' is not a variable
		clicked += 7;
	}
}

Operator overloading applies only for structs and classes (aggregated declarations), not for template declaration, so the expectation that a named mixin should call opCall (like in the above example) is invalid. The patch makes it so that when this.clicked() is rejected by the compiler.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @RazvanN7! 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 coverage diff by visiting the details link of the codecov check)
  • 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
2450 normal Error using operators from named template mixin

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#10406"

@thewilsonator
Copy link
Contributor

mixin Event!() would still allow that, right? its only explicitly naming the mixin that causes the error now?

If so I approve.

@RazvanN7
Copy link
Contributor Author

Yes. It disallows calling opCall when using just the name of the mixin with ().

@dlang-bot dlang-bot merged commit d946890 into dlang:master Sep 14, 2019
@BorisCarvajal
Copy link
Member

While I was trying to fix another issue I discovered a test that is not fixed by this pull, so I'm pushing a patch touching the root of the problem and moving the other test (part of test33() from runnable/mixin1.d) to fail_compilation/fail2450.d.

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