Skip to content

Map Lean's Option to Java's Optional in getIonSerializer%#53

Merged
keyboardDrummer merged 1 commit into
bot/ion-deserializerfrom
bot/fix-option-to-optional
Jun 30, 2026
Merged

Map Lean's Option to Java's Optional in getIonSerializer%#53
keyboardDrummer merged 1 commit into
bot/ion-deserializerfrom
bot/fix-option-to-optional

Conversation

@keyboardDrummer-bot

Copy link
Copy Markdown
Collaborator

Summary

Fixes the getIonSerializer% Java code generator to map Lean's Option α to java.util.Optional<T> instead of nullable T.

Problem

The IfThenElse record was generated as:

public record IfThenElse(
  AstNode<StmtExpr> cond, 
  AstNode<StmtExpr> thenBranch, 
  AstNode<StmtExpr> elseBranch)

The elseBranch field should be Optional<AstNode<StmtExpr>> since the Lean type has Option (AstNode StmtExpr) for that field.

Root Cause

In javaTypeForInfo, the .option elem case was mapped to just javaBoxedTypeForInfo elem (the inner type), which completely drops the optionality from the Java type signature. The serializer correctly handled null checks, but the type system provided no safety.

Fix

  • Type mapping: .option elem now maps to java.util.Optional<{boxedType}> instead of just the raw inner type
  • Serialization: Uses .isPresent() / .get() instead of null checks
  • Ion wire format: Unchanged — still serializes None as Ion null

After

public record IfThenElse(
  AstNode<StmtExpr> cond,
  AstNode<StmtExpr> thenBranch,
  java.util.Optional<AstNode<StmtExpr>> elseBranch)

Testing

  • lake build Strata.DDM.Integration.Java.Gen
  • lake build StrataTest ✓ (583 jobs)

Addresses strata-org/jverify#405 comment."
true

The getIonSerializer% elaborator was mapping Option α to nullable T
(the raw inner type), which dropped the optionality from the Java type
signature. For example, IfThenElse's elseBranch field was generated as
AstNode<StmtExpr> instead of java.util.Optional<AstNode<StmtExpr>>.

This change:
- Maps Option α to java.util.Optional<T> in type signatures
- Updates serialization to use .isPresent()/.get() instead of null checks
- Updates doc comment to reflect the new mapping
@github-actions github-actions Bot added the Java label Jun 30, 2026
@keyboardDrummer
keyboardDrummer merged commit 2d9a633 into bot/ion-deserializer Jun 30, 2026
7 of 8 checks passed
@keyboardDrummer
keyboardDrummer deleted the bot/fix-option-to-optional branch June 30, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants