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

[E0034] Ambiguous Method Call Error #2365

Merged
merged 1 commit into from
Jul 4, 2023
Merged

Conversation

MahadMuhammad
Copy link
Contributor

@MahadMuhammad MahadMuhammad commented Jul 3, 2023

Ambiguous Method Call Error - E0034

Ambiguous Method Call Error - more than one method has the same prototype.

Code Tested from E0034:

// https://doc.rust-lang.org/error_codes/E0034.html
struct Test;

trait Trait1 {
    fn foo();
}

trait Trait2 {
    fn foo();
}

impl Trait1 for Test { fn foo() {} }
impl Trait2 for Test { fn foo() {} }

fn main() {
    Test::foo() // { dg-error "multiple applicable items in scope for: test" } 
    // error, which foo() to call?
}

Output:

mahad@linux:~/Desktop/mahad/gccrs-build$ gcc/crab1 ../mahad-testsuite/E0034.rs  -frust-incomplete-and-experimental-compiler-do-not-use
../mahad-testsuite/E0034.rs:16:11: error: multiple applicable items in scope for: foo [E0034]
   12 | impl Trait1 for Test { fn foo() {} }
      |                        ~~
   13 | impl Trait2 for Test { fn foo() {} }
      |                        ~~
......
   16 |     Test::foo() // { dg-error "multiple applicable items in scope for: test" }
      |           ^~~
../mahad-testsuite/E0034.rs:16:5: error: Failed to resolve expression of function call
   16 |     Test::foo() // { dg-error "multiple applicable items in scope for: test" }
      |     ^~~~

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.

Running TestCases:

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/generics6.rs:26:23: error: multiple applicable items in scope for: test [E0034]
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/generics6.rs:26:18: error: Failed to resolve expression of function call
compiler exited with status 1

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.h: called error function

@MahadMuhammad MahadMuhammad marked this pull request as draft July 3, 2023 11:55
Ambiguous Method Call Error - more than one method
has the same prototype

gcc/rust/ChangeLog:

	* typecheck/rust-hir-path-probe.h: called error function

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
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 there could be a few others but not 100% sure there is code in rust-hir-type-check-expr.cc

visit (HIR::CallExpr) and visit (HIR::MethodCallExpr)

@philberty philberty added this pull request to the merge queue Jul 4, 2023
Merged via the queue into Rust-GCC:master with commit 5406b63 Jul 4, 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

2 participants