Skip to content

gccrs: Add method selection to operator overloading #2321

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

Merged
merged 1 commit into from
Jun 25, 2023

Conversation

philberty
Copy link
Member

@philberty philberty commented Jun 25, 2023

When we do operator overloading we can get multiple candidates and we need to use the optional arguments to filter the candidates event further. In the bug we had:

<integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify against the rhs to figure out that the lhs should be a usize but when we are using the impl blocks we need to use the rhs to ensure that its possible to coerce the rhs to the expected fntype parameter to filter the candidates.

Fixes #2304

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: use new selection filter
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
* typecheck/rust-hir-dot-operator.h: New select prototype
* typecheck/rust-hir-type-check-expr.cc: call select
* typecheck/rust-type-util.cc (try_coercion): new helper
* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

* rust/compile/issue-2304.rs: New test.

When we do operator overloading we can get multiple candidates and we need
to use the optional arguments to filter the candidates event further. In
the bug we had:

  <integer> + <usize>

Without the Add impl blocks for the primitive interger types we unify
against the rhs to figure out that the lhs should be a usize but when we
are using the impl blocks we need to use the rhs to ensure that its
possible to coerce the rhs to the expected fntype parameter to filter the
candidates.

Fixes #2304

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: use new selection filter
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): new slection Filter
	* typecheck/rust-hir-dot-operator.h: New select prototype
	* typecheck/rust-hir-type-check-expr.cc: call select
	* typecheck/rust-type-util.cc (try_coercion): new helper
	* typecheck/rust-type-util.h (try_coercion): helper prototype

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2304.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
@philberty philberty added the bug label Jun 25, 2023
@philberty philberty self-assigned this Jun 25, 2023
@philberty philberty enabled auto-merge June 25, 2023 20:48
@philberty philberty added this pull request to the merge queue Jun 25, 2023
Merged via the queue into master with commit 337ed0f Jun 25, 2023
@philberty philberty deleted the phil/candidates branch June 26, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Multiple candidate method resolution error
1 participant