square / square/wire

Field and message with same name generate invalid code

Open
#800 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

If we have a message that’s unwisely named not-to-pattern, say, taco and a field of that type with the same name, optional taco taco = 1 then the generated code is malformed because Javac cannot differentiate between the field and class name.

Solutions for fixing this are awkward. Do we allocate a different field name? Or always fully-qualify the class?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Reproduce the malformed generated Java with the optional taco taco = 1 example, then trace the generator path that handles fields and message types with identical names. Done means the generated code compiles with Javac and preserves valid access to both the field and its type.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.