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

[E0308] mismatch types on both sides of assignment Operator #2494

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

MahadMuhammad
Copy link
Contributor

Mismatch types - E0308

  • This errorcode emits when there are mismatch types between lhs & rhs of assignment operator & refactored message.

Code Tested from E0308

// ErrorCode::E0308
#![allow(unused)]
fn main() {
    fn plus_one(x: i32) -> i32 { 
        x + 1 
    }
    plus_one("Not a number");       // { dg-error "mismatched types, expected .i32. got .& str." }
    let x: f32 = "Not a float";     // { dg-error "mismatched types, expected .f32. got .& str." }
}

Output:

➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/mismatched-types.rs
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/mismatched-types.rs:7:14: error: mismatched types, expected ‘i32’ got ‘& str’ [E0308]
    4 |     fn plus_one(x: i32) -> i32 {
      |                 ~
......
    7 |     plus_one("Not a number");       // { dg-error "mismatched types, expected .i32. got .& str." }
      |              ^~~~~~~~~~~~~
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/mismatched-types.rs:8:5: error: mismatched types, expected ‘f32’ got ‘& str’ [E0308]
    8 |     let x: f32 = "Not a float";     // { dg-error "mismatched types, expected .f32. got .& str." }
      |     ^~~    ~~~   ~~~~~~~~~~~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.01 (100%)   138k ( 95%)
 TOTAL                              :   0.00          0.00          0.01          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

There are no previous running test cases for this.


gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::emit_type_mismatch): refactored & called error function.

gcc/testsuite/ChangeLog:

* rust/compile/mismatched-types.rs: New test from rustc.

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

Slight nit but looks good otherwise! Thank you!

gcc/rust/typecheck/rust-unify.cc Outdated Show resolved Hide resolved
auto-merge was automatically disabled August 2, 2023 08:28

Head branch was pushed to by a user without write access

@MahadMuhammad
Copy link
Contributor Author

I also updated the test case now, Thanks for review :)

@MahadMuhammad
Copy link
Contributor Author

@CohenArthur Sorry for delay as this message was used in many places in our test suite.

This errorcode emits when there are
mismatch types between lhs & rhs of
assignment operator & refactored
message. This error code was used
in many test cases, so updated the
error comments.

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_type_mismatch):
	refactored & called error function.

gcc/testsuite/ChangeLog:

	* rust/compile/arrays1.rs: changed comment to pass testcase.
	* rust/compile/bad_type1.rs: likewise.
	* rust/compile/bad_type2.rs: likewise.
	* rust/compile/const_generics_6.rs: likewise.
	* rust/compile/deadcode_err1.rs: likewise.
	* rust/compile/deadcode_err2.rs: likewise.
	* rust/compile/func1.rs: likewise.
	* rust/compile/func3.rs: likewise.
	* rust/compile/func4.rs: likewise.
	* rust/compile/func5.rs: likewise.
	* rust/compile/generics1.rs: likewise.
	* rust/compile/generics2.rs: likewise.
	* rust/compile/generics3.rs: likewise.
	* rust/compile/implicit_returns_err1.rs: likewise.
	* rust/compile/implicit_returns_err2.rs: likewise.
	* rust/compile/implicit_returns_err3.rs: likewise.
	* rust/compile/implicit_returns_err4.rs: likewise.
	* rust/compile/issue-1152.rs: likewise.
	* rust/compile/issue-2477.rs: likewise.
	* rust/compile/reference1.rs: likewise.
	* rust/compile/stmt_with_block_err1.rs: likewise.
	* rust/compile/traits1.rs: likewise.
	* rust/compile/traits2.rs: likewise.
	* rust/compile/tuple_mismatch.rs: likewise.
	* rust/compile/tuple_struct3.rs: likewise.
	* rust/compile/mismatched-types.rs: New test from rustc.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
@CohenArthur CohenArthur added this pull request to the merge queue Aug 2, 2023
Merged via the queue into Rust-GCC:master with commit 6c63150 Aug 2, 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 enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants