scalapb/ScalaPB

Cannot name a 'oneof' field 'option' if an optional field exists

Closed this issue · 1 comments

This issue is also potentially connected with #1462.

Problem description:
When a .proto file contains a message with both a nested message field and a oneof field named option, the scalapb compiler generates an object Option and in the parseFrom method's pattern matching, it uses Option without specifying the Scala package (_root_.scala.Option). This causes the Scala compiler to produce an error, as it interprets Option as the generated object Option rather than the standard Scala Option, which does not take parameters.

Steps to reproduce:

  1. Create PaymentMethod.proto file with contents:
message PaymentMethod {
  string id = 1;
  Money amount = 2;
  oneof option {
    CreditCard credit_card = 3;
    DebitCard debit_card = 4;
    PayPal pay_pal = 5;
  }
}
  1. Compile .proto file
  2. Observe the resulting error in object PaymentMethod within the parseFrom function: "object Option in object PaymentMethod does not take parameters."

Thanks for reporting and providing the steps to reproduce. Fixed!