Skip to content

Fix fpp-to-cpp dropping rational format fields on aliases of F32 and F64 - #1119

Merged
bocchino merged 1 commit into
nasa:release/v3.3.1from
Dev-next-gen:fix-format-alias-float
Sep 21, 2026
Merged

bocchino merged 1 commit into
nasa:release/v3.3.1from
Dev-next-gen:fix-format-alias-float

Conversation

@Dev-next-gen

@Dev-next-gen Dev-next-gen commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor
Related Issue(s) Fixes #1116
Has Unit Tests (y/n) y
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) y

Change Description

FormatCppWriter.writeField dispatched the rational (floating-point) format case on the syntax of the type-name node, so a type alias whose underlying type is F32 or F64 never matched Ast.TypeNameFloat and fell through to the default %f. The integer case already dispatched on the denoted type; this change does the same for the rational case, resolving the alias before selecting the conversion. No FPP or interface change.

Also:

  • A new test case alias_type.fpp under compiler/tools/fpp-to-cpp/test/array, exercising an array element whose type is an F32 alias with a rational format, plus the regenerated reference outputs (ATF32AliasAc, AliasTypeFormatArrayAc) and the run.sh / update-ref.sh updates that include it.

Rationale

Fixes #1116. With type ATF32 = F32 and a format of {.3e}, semantic checking resolves the alias and accepts the format, but fpp-to-cpp then emitted tmp.format("%f", ...) instead of "%.3e": the precision and the e conversion were silently dropped, while the same array declared with F32 directly produced "%.3e".

Testing/Review Recommendations

  • The new alias_type.fpp reference outputs now show %.3e where the old code produced %f; with only FormatCppWriter.scala reverted and the test kept, the reference comparison fails on exactly that difference.
  • The production change is two lines in FormatCppWriter.scala, reusing the dispatch the integer case already does.

Future Work

None.

AI Usage (see policy)

This contribution comes out of a defect-hunting pipeline I build and run (Dev-next-gen). It uses Claude Code with Anthropic's Claude Opus 5.

  • Type of assistance: finding the defect, the code change, the unit test case, and the text of this PR and the issue.
  • Scope: everything in this PR — the rational-format dispatch in FormatCppWriter.scala, the new alias_type.fpp case and its regenerated reference outputs under compiler/tools/fpp-to-cpp/test/array.
  • How it was found: the pipeline searched fpp-to-cpp code generation for cases where a resolved type alias is treated differently from its underlying type, and found the rational format field dropped on aliases of F32/F64 while the integer case handled them.
  • Level of modification: the change intentionally reuses the existing integer-case pattern (dispatch on the denoted type) rather than a new one. Nothing leaves the pipeline without a test that fails before the change and passes after it, run with the project's own tooling.

IAMAI

"Nothing this pipeline produces is submitted without human approval. The entire pull request — the code change, the test case and its reference outputs, and this description — was reviewed by a human before the pipeline was allowed to submit it."

(@Dev-next-gen)

When a telemetry channel, event parameter, struct member, or array element
is declared with a type alias whose underlying type is F32 or F64, the C++
writer dropped the rational format field and emitted the default %f.
Semantic checking already resolves the alias, so `type T = F32` with a
format of `{.3e}` passes the checks and then generates `%f`: the precision
and the conversion are silently lost.

FormatCppWriter.writeField dispatched the rational case on the syntax of
the type name node rather than on the type it denotes, so an alias name
never matched Ast.TypeNameFloat. The integer case already dispatched on
the underlying type; do the same for the rational case.

@Kronos3 Kronos3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@bocchino bocchino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@bocchino
bocchino merged commit e0ab170 into nasa:release/v3.3.1 Sep 21, 2026
14 checks passed
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.

3 participants