Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5414

Use of specific parameter names generates uncompileable code

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.15.0
    • Component/s: netstd - Compiler
    • Labels:
      None

      Description

      The csharp service client generator creates some local variables that prevent the usage of those names in the Thrift file.

       For example the following thrift file breaks:

      service Test {
          void Calculate( 
      		1 : i32 x, # This breaks because the variable name x is the same as the TApplicationException variable name x
      		2 : i32 result, # This breaks because the variable name result is the same as the InternalStructs variable name result
      	)
      }
      

      The above example will generate the following C# code which does not compile because x and result are also used below:

      public async global::System.Threading.Tasks.Task Calculate(int x, int result, CancellationToken cancellationToken = default)
      {
          await OutputProtocol.WriteMessageBeginAsync(new TMessage("Calculate", TMessageType.Call, SeqId), cancellationToken);
          
          var args = new InternalStructs.CalculateArgs() {
              X = x,
              Result = result,
          };
          
          await args.WriteAsync(OutputProtocol, cancellationToken);
          await OutputProtocol.WriteMessageEndAsync(cancellationToken);
          await OutputProtocol.Transport.FlushAsync(cancellationToken);
          
          var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);
          if (msg.Type == TMessageType.Exception)
          {
              var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);
              await InputProtocol.ReadMessageEndAsync(cancellationToken);
              throw x;
          }
      
          var result = new InternalStructs.CalculateResult();
          await result.ReadAsync(InputProtocol, cancellationToken);
          await InputProtocol.ReadMessageEndAsync(cancellationToken);
          return;
      }
      

      When compiling this code with `-gen java` the generated sources build fine.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jensg Jens Geyer
                Reporter:
                thomasbruggink Thomas Bruggink
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m