Skip to content

erroneous compilation with 'Call' as rpc identifier #963

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
kaduvert opened this issue Feb 24, 2025 · 1 comment · Fixed by #964
Closed

erroneous compilation with 'Call' as rpc identifier #963

kaduvert opened this issue Feb 24, 2025 · 1 comment · Fixed by #964

Comments

@kaduvert
Copy link

i'm not sure if my .proto is valid but it worked for other things so assumed so:

syntax = "proto3";

message Default {
  string id = 1;
  string content = 2;
  optional string auth = 3;
}

service DefaultService {
  rpc Call(Default) returns (Default);
}

so the problem seems to be that the rpc of DefaultService is named Call, which causes problems when compiling for dart:

//
//  Generated code. Do not modify.
//  source: default.proto
//
// @dart = 2.12

// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import

import 'dart:async' as $async;
import 'dart:core' as $core;

import 'package:grpc/service_api.dart' as $grpc;
import 'package:protobuf/protobuf.dart' as $pb;

import 'default.pb.dart' as $0;

export 'default.pb.dart';

@$pb.GrpcServiceName('DefaultService')
class DefaultServiceClient extends $grpc.Client {
  static final _$call = $grpc.ClientMethod<$0.Default, $0.Default>(
      '/DefaultService/Call',
      ($0.Default value) => value.writeToBuffer(),
      ($core.List<$core.int> value) => $0.Default.fromBuffer(value));

  DefaultServiceClient($grpc.ClientChannel channel,
      {$grpc.CallOptions? options,
      $core.Iterable<$grpc.ClientInterceptor>? interceptors})
      : super(channel, options: options,
        interceptors: interceptors);

  $grpc.ResponseFuture<$0.Default> call($0.Default request, {$grpc.CallOptions? options}) {
    return $createUnaryCall(_$call, request, options: options);
  }
}

@$pb.GrpcServiceName('DefaultService')
abstract class DefaultServiceBase extends $grpc.Service {
  $core.String get $name => 'DefaultService';

  DefaultServiceBase() {
    $addMethod($grpc.ServiceMethod<$0.Default, $0.Default>(
        'Call',
        call_Pre,
        false,
        false,
        ($core.List<$core.int> value) => $0.Default.fromBuffer(value),
        ($0.Default value) => value.writeToBuffer()));
  }

  $async.Future<$0.Default> call_Pre($grpc.ServiceCall call, $async.Future<$0.Default> request) async {
    // 1)
    return call(call, await request);
  }

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

this file is called default.pbgrpc.dart and is part of the output

the problem:
so when trying to execute it, it complains about how something is wrong at 1) and how call doesnt work

my temporary workaround and possible fix inspiration:
renaming the function that's trying to be called at 1) and 2) to asdasd

I'm using protoc 29.2 on linux

@osa1
Copy link
Member

osa1 commented Feb 25, 2025

Thanks for reporting. I think this is a duplicate of #159, but the names that clash are different.

The argument name call clashes with the RPC method name call, causing type error in this line:

$async.Future<$0.Default> call_Pre($grpc.ServiceCall call, $async.Future<$0.Default> request) async {
  return call(call, await request); // <------------ HERE
}

We should add a prefix or suffix to the all argument names (using characters not allowed in .proto files but allowed in .dart files) we generate to make sure they won't clash with method names generated from names specified by the user.

I'll fix this but in the meantime, you can give another name to your call RPC method.

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