btlines / grpcakkastream

Use GRPC services with the Akka-stream API
MIT License
69 stars 12 forks source link

Fix name clashes with AnyRef’s methods #16

Closed danielyli closed 6 years ago

danielyli commented 6 years ago

gRPC methods named clone, finalize, notify, notifyAll, or wait currently cause grpcakkastream to generate invalid code:

Compilation output (click to expand)
[error] ./target/scala-2.11/src_managed/main/com/tubitv/rpc/TestServiceGrpcAkkaStream.scala:383
         type mismatch;
[error]  found   : Unit
[error]  required: akka.stream.Graph[akka.stream.FlowShape[com.tubitv.rpc.In,?],?]
[error]                 .via(serviceImpl.notify)
[error]                                  ^
[error] ./target/scala-2.11/src_managed/main/com/tubitv/rpc/TestServiceGrpcAkkaStream.scala:384
         missing argument list for method onNext in trait StreamObserver
[error] Unapplied methods are only converted to functions when a function type is expected.
[error] You can make this conversion explicit by writing `onNext _` or `onNext(_)` instead of `onNext`.
[error]                 .runForeach(responseObserver.onNext)
[error]                                              ^
[error] two errors found
[error] (compile:compileIncremental) Compilation failed


This occurs because these five parameterless methods are marked final (or, in the case of clone, protected) in AnyRef. Generating a homonymous method leads the Scala compiler to think we’re trying to override these methods.

This PR fixes this issue by appending an underscore to these method names in the generated code.

btlines commented 6 years ago

It makes sense. Thanks!