Skip to content

Avoid generating syntax errors for capitalized protobuf fields#878

Merged
Morriar merged 1 commit intomainfrom
at-fix-protobuf
Mar 29, 2022
Merged

Avoid generating syntax errors for capitalized protobuf fields#878
Morriar merged 1 commit intomainfrom
at-fix-protobuf

Conversation

@Morriar
Copy link
Contributor

@Morriar Morriar commented Mar 29, 2022

Motivation

With Protobuf it seems possible to write fields with capitalized names:

add_message "MyCart" do
  optional :ShopID, :int32, 1
  optional :ShopName, :string, 2
end

In its current state, Tapioca will generate a syntactically incorrect RBI:

class Cart
  sig { params(ShopID: String, ShopName: String).void }
  def initialize(ShopID: nil, ShopName: nil); end # Syntax error: formal argument cannot be a constant

  # ...
end

While we do want to generate constructors with named fields, we could fallback on taking a Hash if the name of one of the field is not suitable for a named parameter:

class Cart
  sig { params(fields: T.untyped).void }
  def initialize(**fields); end
end

Tests

See automated tests.

@Morriar Morriar added the bugfix label Mar 29, 2022
@Morriar Morriar requested a review from a team March 29, 2022 20:46
@Morriar Morriar self-assigned this Mar 29, 2022
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar merged commit a105dc2 into main Mar 29, 2022
@Morriar Morriar deleted the at-fix-protobuf branch March 29, 2022 23:25
paracycle pushed a commit that referenced this pull request Apr 29, 2022
Avoid generating syntax errors for capitalized protobuf fields
@paracycle paracycle added the backported Backported to stable branch label Apr 29, 2022
@shopify-shipit shopify-shipit bot temporarily deployed to production May 13, 2022 23:08 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported Backported to stable branch bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants