Skip to content

Generated code contains error "is not a function call" for basic sample .proto #159

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

Closed
Meai1 opened this issue Jul 7, 2018 · 5 comments · Fixed by #964
Closed

Generated code contains error "is not a function call" for basic sample .proto #159

Meai1 opened this issue Jul 7, 2018 · 5 comments · Fixed by #964
Labels

Comments

@Meai1
Copy link

Meai1 commented Jul 7, 2018

This file creates a problem:

syntax = "proto2";
service PeerService {
    rpc Request (Message) returns (Message) {}
}
message Message {
}

Workaround:
If I rename the "Request" method to anything else, it generates error free code. I think it should work anyway though, seems weird that it breaks on a certain identifier.

@sigurdm
Copy link
Collaborator

sigurdm commented Aug 21, 2018

Thanks for reporting this.
I have a fix coming up for this, I just need to write a regression test for it.

@mit-mit mit-mit transferred this issue from dart-archive/dart-protoc-plugin Dec 14, 2018
@osa1
Copy link
Member

osa1 commented Apr 11, 2022

This looks like a grpc-dart issue. Should we close it? I learned recently that rpc syntax is handled by this library.

@osa1
Copy link
Member

osa1 commented Apr 28, 2022

I talked to @sigurdm about this. The issue is in this generated code:

abstract class PeerServiceBase extends $grpc.Service {
  $async.Future<$0.Message> request_Pre(
      $grpc.ServiceCall call, $async.Future<$0.Message> request) async {
    return request(call, await request); // <-------- this line
  }

  $async.Future<$0.Message> request($grpc.ServiceCall call, $0.Message request);
}

In the marked line above, the first request is supposed to be the request method a few lines below, but the request argument shadows it, causing the error.

The argument name is hard-coded as request. The method at the bottom is generated based on RPC method name.

rpc Call ... also reproduces the issue as we also have an argument in ..._Pre method with name call.

To fix this we should avoid shadowing stuff with argument names in generated methods. We should somehow make sure we generate unique names for arguments. Depending on how we generate method names it may suffice to add $_ prefix, or some suffix etc. to the argument names.

@osa1
Copy link
Member

osa1 commented Apr 28, 2022

@sigurdm points out that we could also add this. to the method call. I like this approach more as we don't have to think about unique argument name generation.

@osa1
Copy link
Member

osa1 commented May 11, 2022

#485 is the same issue but the method name is New instead of Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants