Skip to content

fix(compiler): fix Java, Kotlin and Scala codegen emission bugs - #4109

Open
ayush00git wants to merge 3 commits into
apache:mainfrom
ayush00git:fix/jvm-generator-emission
Open

ayush00git wants to merge 3 commits into
apache:mainfrom
ayush00git:fix/jvm-generator-emission

Conversation

@ayush00git

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes five code-emission bugs in the Java, Kotlin and Scala compiler generators:

  • Java: union cases of duration/decimal types emitted Types.UNKNOWN instead of Types.DURATION/Types.DECIMAL, producing a wrong wire type id.
  • Java: reserved-word field names were never escaped, so a field such as string class = 1; generated private String class;, which does not compile; a field or union case named class also generated getClass(), clashing with the final Object.getClass().
  • Java: optional list elements and map values lost the @Nullable type-use annotation, so generated Java treated them as non-null while Kotlin, Scala and Go emit nullable for the same schema.
  • Java/Kotlin/Scala: a schema type named after a module-file runtime import (e.g. message Fory) compiled but silently registered the wrong class; registrations of shadowed names are now package-qualified, and a shadowed name in the default package is rejected with a clear error.
  • Kotlin: message Empty {} generated data class Empty(), which does not compile; empty messages now use a plain class.

Verification

Regression tests added for each bug; each fails without its corresponding generator fix. Full compiler suite passes: python3 -m pytest fory_compiler/tests -q (500 passed, 1 skipped).

- java: union cases of duration/decimal types emitted Types.UNKNOWN
  instead of Types.DURATION/Types.DECIMAL, writing a wrong wire type id.
- java: reserved-word field names were never escaped, so a field such as
  `string class = 1;` generated invalid Java; a field or union case
  named `class` also generated getClass(), clashing with the final
  Object.getClass().
- java: optional list elements and map values lost the @nullable
  type-use annotation, diverging from Kotlin/Scala/Go output for the
  same schema.
- java/kotlin/scala: a schema type named after a module-file runtime
  import (e.g. `message Fory`) compiled but silently registered the
  wrong class; registrations of shadowed names are now
  package-qualified, and a shadowed name in the default package is
  rejected.
- kotlin: `message Empty {}` generated `data class Empty()`, which does
  not compile; empty messages now use a plain class.

Claude-Session: https://claude.ai/code/session_01YcPbRyTJYmU8t6mkGCbnUf
@ayush00git
ayush00git requested a review from chaokunyang October 2, 2026 04:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant