Skip to content

[Repo Assist] docs: clarify reachability of TODO branches in JSON code generator#1716

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/json-codegen-dead-code-cleanup-1d067e122892e0b5
Draft

[Repo Assist] docs: clarify reachability of TODO branches in JSON code generator#1716
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/json-codegen-dead-code-cleanup-1d067e122892e0b5

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Replaces three long-standing //TODO: not covered in tests comments in the JSON code generator with accurate explanations of why each branch is not reached in practice. No behaviour changes.

Motivation

These //TODO comments have existed since the TypeWrapper-based code-generation infrastructure was first introduced. They were correct in spirit (the branches are genuinely not exercised by the test suite) but misleading in implication — they suggest "add tests" when the actual situation is that the branches are structurally unreachable given how JSON inference works today.

After tracing the full call graph, the findings are:

JsonConversionsGenerator.fsconvertJsonValue

Branch Reachability
TypeWrapper.Option, false Structurally possible (called when canPassAllConversionCallingTypes=false, e.g. for array element types), but not reachable in practice — JSON null-stripping in generateJsonType strips Null tags from collections before element types are processed, preventing optional primitives from appearing as array elements. Comment now documents the intended semantics.
TypeWrapper.Nullable, true Dead code — JSON inference only ever emits TypeWrapper.None or TypeWrapper.Option (via PrimitiveInferedValue.Create(_, bool, _)). TypeWrapper.Nullable requires explicit "int?" schema annotations which are blocked for JSON by StructuralInference.parseTypeAndUnit. Retained for structural completeness / future extensibility.
TypeWrapper.Nullable, false Same as above.

JsonGenerator.fsgetter for object members

Branch Reachability
ConvertOptionalProperty arm Requires prop.Type.IsOptional = true AND ConversionCallingType = JsonDocument AND OptionalConverter = Some _. This combination would need InferedType.Json(optional=true), but InferedType.Json is rejected by generateJsonType with failwith "Json type not supported". Dead code in practice.

Change Details

  • src/FSharp.Data.DesignTime/Json/JsonConversionsGenerator.fs — 3 //TODO: not covered in tests replaced with detailed explanatory comments
  • src/FSharp.Data.DesignTime/Json/JsonGenerator.fs — 1 //TODO: not covered in tests replaced with detailed explanatory comment

Test Status

  • dotnet build src/FSharp.Data.DesignTime/FSharp.Data.DesignTime.fsproj — 0 errors, 15 pre-existing warnings
  • dotnet test tests/FSharp.Data.Core.Tests — 2896 passed
  • ⚠️ dotnet test tests/FSharp.Data.DesignTime.Tests — 436 failures (pre-existing infrastructure failures identical on main before this change, unrelated to the comment updates)

Generated by Repo Assist

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

Replace three misleading '//TODO: not covered in tests' comments in
JsonConversionsGenerator.fs and JsonGenerator.fs with accurate
explanations of WHY those branches are not exercised in practice.

JsonConversionsGenerator.fs – convertJsonValue:
- TypeWrapper.Option, false: reachable in principle (called when
  canPassAllConversionCallingTypes=false, e.g. for array element
  types), but currently unreachable in practice because JSON null-
  stripping prevents optional primitives from appearing as array
  elements. Document the intended semantics clearly.
- TypeWrapper.Nullable, true/false: JSON inference only ever emits
  TypeWrapper.None or TypeWrapper.Option. These branches exist for
  structural completeness and potential future extensibility.

JsonGenerator.fs – generateObjectMembers getter (ConvertOptionalProperty):
- Requires a property whose type is IsOptional=true AND whose
  ConversionCallingType is JsonDocument AND which has an
  OptionalConverter. This combination requires InferedType.Json(optional=true),
  which the JSON provider does not currently produce.

No behaviour change; pure documentation improvement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants