-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Check for calling of associated functions as method calls. #2198
Conversation
9b6dc71
to
c80572f
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.
This is an awesome change and great for compiler UX. Thanks!
test/src/e2e_vm_tests/test_programs/should_fail/associated_fn_as_method_call/Forc.toml
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_fail/associated_fn_params_as_method_call/Forc.toml
Outdated
Show resolved
Hide resolved
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.
I agree with what Alex said, but other than that LGTM. When those changes go through I will approve.
4a7ef01
to
a6f60cc
Compare
Merge conflicts! |
This adds a new error and checking for calls of associated functions using method call syntax. This means for code like the following: ``` struct Bar {} impl Bar { fn associated() {} } fn main() -> u64 { let bar = Bar {}; bar.associated(); 0 } ``` we now emit an error: ``` error --> main.sw:11:3 | 9 | 10 | let bar = Bar {}; 11 | bar.associated(); | ^^^^^^^^^^^^^^^^ Cannot call associated function "associated" as method call. Use associated function syntax instead. 12 | 0 13 | } | ``` This brings us closer to Rust behaviour, which also checks for this and only allows functions taking a self to be called with method call syntax. It adds a few more tests for this and also updates some standard library trait methods to take self so they work with the new check.
a6f60cc
to
3ca7651
Compare
@sezna this PR requires your review again :) |
…2198) This adds a new error and checking for calls of associated functions using method call syntax. This means for code like the following: ``` struct Bar {} impl Bar { fn associated() {} } fn main() -> u64 { let bar = Bar {}; bar.associated(); 0 } ``` we now emit an error: ``` error --> main.sw:11:3 | 9 | 10 | let bar = Bar {}; 11 | bar.associated(); | ^^^^^^^^^^^^^^^^ Cannot call associated function "associated" as method call. Use associated function syntax instead. 12 | 0 13 | } | ``` This brings us closer to Rust behaviour, which also checks for this and only allows functions taking a self to be called with method call syntax. It adds a few more tests for this and also updates some standard library trait methods to take self so they work with the new check. Co-authored-by: Emily Herbert <17410721+emilyaherbert@users.noreply.github.com> Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
This adds a new error and checking for calls of associated functions using method call syntax.
This means for code like the following:
we now emit an error:
This brings us closer to Rust behaviour, which to my understanding also checks for this and only allows method call syntax for functions taking self.
It adds a few more tests for this and also updates some standard library trait methods to take self so they work with the new check.