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

[E0061] Refactored argument mismatch error function #2373

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

MahadMuhammad
Copy link
Contributor

@MahadMuhammad MahadMuhammad commented Jul 4, 2023

Argument Mismatch Error-E0061

  • Refactored argument mismatch error into one function emit_unexpected_argument_error.
  • Changed unexpected argument message to similiar to rustc.
  • You can view the same on compiler-explorer:
- unexpected number of arguments x expected y [E0061]
+ this function takes y arguments but x arguments were supplied [E0061]

Code Tested:

// https://doc.rust-lang.org/error_codes/E0061.html
fn main() {
    fn f(u: i32) {}
    fn T(u: i32, v: i32, w: i32, x: i32, y: i32, z: i32) {}

    f(); // { dg-error "this function takes 1 argument but 0 arguments were supplied" }

    T(1, 2, 3, 4, 5, 6, 7, 8, 9); // { dg-error "this function takes 6 arguments but 9 arguments were supplied" }
}

Output:

/gccrs/gcc/testsuite/rust/compile/func2.rs:6:13: error: this function takes 2 arguments but 1 arguments were supplied [E0061]
compiler exited with status 1

/gccrs/gcc/testsuite/rust/compile/tuple_struct2.rs:4:13: error: this function takes 3 arguments but 2 arguments were supplied [E0061]
compiler exited with status 1

/gccrs/gcc/testsuite/rust/compile/unexpected_arguments.rs:6:5: error: this function takes 1 arguments but 0 arguments were supplied [E0061]
/gccrs/gcc/testsuite/rust/compile/unexpected_arguments.rs:7:5: error: this function takes 6 arguments but 9 arguments were supplied [E0061]
compiler exited with status 1

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error): Refactored invalid number of argument into one function. (TypeCheckCallExpr::visit): called refactored function. (TypeCheckMethodCallExpr::check): called refactored function.

gcc/testsuite/ChangeLog:

* rust/compile/func2.rs: updated comment to pass new test cases.
* rust/compile/tuple_struct2.rs: updated comment.
* rust/compile/unexpected_arguments.rs: Added new test.

@MahadMuhammad MahadMuhammad changed the title [E0061] Unexpected number of Arguments [E0061] Refactored argument mismatch error function Jul 4, 2023
@MahadMuhammad
Copy link
Contributor Author

MahadMuhammad commented Jul 4, 2023

  • rustc treats 1 as singular while all others numbers as plural.

  • You can also test this on compiler-explorer

    • this function takes 1 argument but 0 arguments were supplied
    • this function takes 0 arguments but 1 argument was supplied

Should I also add this?

  • Done

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

LGTM just remove the return statement.

gcc/rust/typecheck/rust-tyty-call.cc Outdated Show resolved Hide resolved
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

This should be fixed with dg-error.

If not i will take another look when you update the PR. Also take a look at your rust.log output too.

gcc/testsuite/rust/compile/unexpected_arguments.rs Outdated Show resolved Hide resolved
gcc/testsuite/rust/compile/unexpected_arguments.rs Outdated Show resolved Hide resolved
Added Invalid number of arguments (argument mismatch)
was passed when calling a function - unexpected
number of arguments `x` expected `y` And Refactored
error into one function.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error):
	Refactored invalid number of argument into one function.
	(TypeCheckCallExpr::visit): called refactored function.
	(TypeCheckMethodCallExpr::check): likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/func2.rs: updated comment to pass new test cases.
	* rust/compile/tuple_struct2.rs: likewise.
	* rust/compile/wrong_no_of_parameters.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
@philberty philberty added this pull request to the merge queue Jul 9, 2023
Merged via the queue into Rust-GCC:master with commit f7a29f5 Jul 9, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants