Fail codegen for powered unit prefixes - #1702
Conversation
Review: Fail codegen for powered unit prefixesNice, tightly-scoped follow-up to #1700 for adding a guard so this class of bug ( Breaking changes New quantities/units Generated code changes Style and conventions Possible issues / suggestions
Test coverage Performance / Security Overall: a solid, low-risk guard that matches the intent described in the PR. The two items above (redundant per-prefix check, generic exception rewrap) are minor polish, not blockers. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1702 +/- ##
======================================
Coverage 96% 96%
======================================
Files 457 457
Lines 29301 29301
======================================
Hits 28239 28239
Misses 1062 1062
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…degen' into agl-codex/fail-powered-prefix-codegen # Conflicts: # CodeGen/Helpers/PrefixBuilder/UnitPrefixBuilder.cs
ReviewReviewed the diff ( Breaking changesNone for library consumers. This only adds a build-time guard in Style & conventions
Generated code changesNone — this PR doesn't touch generators that emit Code quality / correctness
Test coverageThere's no dedicated test project for Other
Overall a well-scoped, low-risk, backward-compatible guard that directly follows up on the |
|
Review: Fail codegen for powered unit prefixes (#1702) Good, focused follow-up to #1700 — this closes the loop by making CodeGen fail loudly instead of relying on developers remembering the rule. Reviewed Breaking changes Correctness of the heuristic The regex itself is reasonably careful (anchored at One thing worth double-checking: the guard only inspects Style/structure Minor/nit Test coverage Overall |
ReviewReviewed as a follow-up to #1700: adds a CodeGen guard that fails the build when Breaking changes Generated code Code quality
Minor/nit
Test coverage Security Overall this is a small, well-targeted, well-documented safety net with no impact on currently generated code. Nice follow-up to #1700. |
ReviewReviewed the diff ( Breaking changesNone. This only affects code generation; it fails the build if a future JSON definition misuses Regression risk (no existing units break)I sampled several quantities that combine
I didn't find a case among the ~90 JSON files using Code quality / potential gap
Minor style nit: The refactor from the flat Test coverageThere's no DocsThe schema doc update is clear and gives good concrete examples ( SummarySolid, narrowly-scoped guard that matches its stated goal, with good regex documentation (remarks explicitly list what it does not catch, which is honest about the heuristic's limits). No breaking changes, no new units. Only real suggestion is considering whether |
|
Review of #1702: Fail codegen for powered unit prefixes Nice, focused change: it closes a real gap (e.g. accidentally regenerating something like km-cubed for CubicMeter) with a narrowly scoped heuristic rather than a full unit-expression parser. A few notes. Breaking changes: Generated code changes: New quantities/units: Code quality / correctness:
Test coverage: Performance / security: Overall: solid, well-documented guardrail that matches the pattern established in #1700. Nothing blocking. |
Motivation
Follow-up to #1700.
We should fail codegen when
Prefixesis used on units that look like powered units themselves, such asSquareMeter,CubicMeter, or abbreviations starting withm²,m³,ft³, and similar symbols.That avoids reintroducing bugs like
KilocubicMeterformatting askm³, where the generated prefix looks like it applies before the length unit is cubed.This is intentionally narrower than checking base dimensions. Units like
Megawatt,Megajoule, andMegaohmstill need to be allowed even though their SI base dimensions contain exponents internally.Changes
Prefixeson units that look like powered units.Validation
dotnet build CodeGen\CodeGen.csprojgenerate-code.batPrefixes: [ "Kilo" ]toArea.SquareMeterand verified CodeGen fails with the new error, then reverted the temporary edit.