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

fix(build): Remove ambiguity in service method call #327

Merged
merged 1 commit into from
Apr 9, 2020

Conversation

yonran
Copy link
Contributor

@yonran yonran commented Apr 7, 2020

Motivation

I have an existing proto with a method that was unfortunately named Drop, and the tonic stub did not compile. When calling methods on Arc where the method is also defined on Arc (e.g. drop and clone), calling inner.#method_ident(request) will actually attempt to call the Arc method instead of the method on the service, resulting in a compile error when building the generated rust file.

Here is an excerpt from a test proto, which I have added as tests/ambiguous_methods/proto/ambiguous_methods.proto:

service HelloService {
    rpc Drop (DropReq) returns (DropResp);
    rpc Clone (DropReq) returns (DropResp);
}

Solution

This change removes the ambiguity by dereferencing the inner Arc.

An alternative fix would be to use the fully qualified syntax for method calls. I believe that this change should be good enough because #server_trait is only known to be #server_trait : Send + Sync + 'static, and Sync and Send define no other methods.

See also: my PR to grpc-rust for the exact same issue a year ago stepancheg/grpc-rust#142

When calling methods on Arc<MyService> where the method is also defined on Arc (e.g. drop and clone), calling inner.#method_ident(request) will actually attempt to call the Arc method instead of the method on the service, resulting in a compile error. This change removes the ambiguity by dereferencing the inner Arc.
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

Great catch! and nice fix! I will get a bump release out.

@LucioFranco LucioFranco changed the title Dereference the Arc before invoking methods on the service fix(build): Remove ambiguity in service method call Apr 9, 2020
@LucioFranco LucioFranco merged commit 5d56daa into hyperium:master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants