Make a quantity default compile, and take the two SonarCloud findings - #190
Merged
Merged
Conversation
S3358: Measured had a nested ternary. The first branch is a guard - a quantity knows its own dimension and nothing else needs asking - so it reads as one. S3218: QuantityInfo.Components is the property a caller reads, and a private Components(Type) on the enclosing class shadowed it from inside the record. The helper is now ComponentsOf, which also matches DimensionOf beside it: both are named for the question rather than the answer. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UGHDsYaaTQdzVR4XBR6miu
A generated C++ quantity refuses a bare number twice over. Its own
constructor is explicit - a bare value never becomes a Mass by accident -
and so is the constructor of the Quantity that constructor takes. So
`holo::Mass{ 1.0f }` is not one conversion the compiler will make but
two, and the header the generator wrote did not compile against the
vocabulary it named.
What compiles is the step said out loud:
`holo::Mass{ holo::Mass::underlying{ 1.0f } }`. A vector form spells the
same alias `component` and takes one per component, so a single default
starts every component there - the same reading a numeric default on a
built-in vector already gets.
Two smaller things were wrong with the same line. CppFileBuilder's
Represented did not follow a quantity to its storage, so a float-stored
quantity got `1` rather than `1.0f` - an int literal a braced initialiser
refuses for narrowing, which is the whole reason to brace it.
Both alias names are ktsu.Semantics.Cpp's, which is a coupling rather
than a deduction: CppGeneratorOptions.Quantities is the target saying its
vocabulary came from there. So it is compiled rather than assumed. The
stub vocabularies in both test files are now explicit in both places
instead of being aggregates that would have accepted either spelling, and
TheModernisedSampleCompiles exercises it on a real sample, whose gravity
has a default.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UGHDsYaaTQdzVR4XBR6miu
|
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Two commits following #189. The first is cleanup; the second is a bug in what #189 shipped, found while preparing Holotype to consume it.
A quantity default did not compile
#189'sQuantityCppTestscompiled a promising class of quantities, but none of them had a default. Holotype'srigid_body.schema.jsondoes —Massstarts at 1.0,Restitutionat 0.5,Radiusat 0.5 — and that is where it falls over.A generated C++ quantity refuses a bare number twice over. Its own constructor is explicit — "a bare value never becomes a
Massby accident" — and so is the constructor of theQuantitythat constructor takes:So
holo::Mass{ 1.0f }is not one conversion the compiler will make but two, and the header the generator wrote did not compile against the vocabulary it had just been told to name. What compiles is the step said out loud:holo::Mass mass = holo::Mass{ holo::Mass::underlying{ 1.0f } };A vector form spells the same alias
componentand takes one per component, so a single default starts every component there — the same reading a numeric default on a built-in vector already gets.A second thing was wrong on the same line:
CppFileBuilder.Representeddid not follow a quantity to its storage, so a float-stored quantity got1rather than1.0f— an int literal a braced initialiser refuses for narrowing, which is the whole reason to brace it.The alias names are
ktsu.Semantics.Cpp's, which is a coupling rather than a deduction:CppGeneratorOptions.Quantitiesis the target saying its vocabulary came from there. So it is compiled rather than assumed. The stub vocabularies in both test files are now explicit in both places instead of being aggregates that would have accepted either spelling — so the new test fails if the generator goes back to the single brace — andTheModernisedSampleCompilesexercises it on a real sample, whosegravityhas a default of-9.81.The two SonarCloud findings
The gate passed on #189 but reported two new issues, and it merged before the fix landed. Both are on code #189 added.
S3358 (major) —
CppReflectionBuilder.Measuredhad a nested ternary. The first branch is a guard rather than an alternative: a quantity knows its own dimension, so nothing else needs asking. Written as one, the remaining ternary is the honest either/or between a unit that resolves and one that does not.S3218 (critical) —
QuantityInfo.Componentsis the property a caller reads, and a privateComponents(Type)on the enclosingQuantityRegistryshadowed it from inside the record. The helper is nowComponentsOf, which also puts it alongsideDimensionOf: both are named for the question rather than the answer.Tests
775 → 779, all passing.
QuantityCppTestsgainsADefaultIsConstructedTheWayTheVocabularyAcceptsIt, which checks the nesting and then compiles it under-std=c++20 -Wall -Wextra.🤖 Generated with Claude Code
https://claude.ai/code/session_01UGHDsYaaTQdzVR4XBR6miu