Skip to content

QuantitiesGenerator emits a factory for only the first availableUnit #48

@matt-edmondson

Description

@matt-edmondson

Summary

The QuantitiesGenerator produces a single From{Unit}(T value) static factory per quantity type, regardless of how many entries availableUnits has in dimensions.json. As a result, generated quantities expose only the SI base unit factory and there is no way to construct values from any of the other declared units.

Evidence

Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs:369-385 only iterates the first unit when emitting From* factories.

Confirmed in generated output, e.g. Semantics.Quantities/Generated/.../Mass.g.cs:

public static Mass<T> FromKilogram(T value) => Create(value);

There is no FromGram, FromMilligram, FromTonne, etc. Same pattern across every generated file (e.g. Length only emits FromMeter, with no FromCentimeter, FromKilometer, FromFoot, FromInch, FromYard, FromMile).

Impact

  • The user-facing API documented in docs/strategy-unified-vector-quantities.md (e.g. Speed.FromMetersPerSecond(...), Force1D.FromNewtons(...)) is partially missing for any non-base unit.
  • Forces consumers to manually convert before calling From{BaseUnit}, defeating a core ergonomics goal of the library.

Suggested next step

Update the generator to emit a From{Unit} factory for every entry in availableUnits, applying the unit's conversion factor (read from the units metadata / ConversionsGenerator) so the value is normalised to the SI base unit inside the factory.

Area / Severity

SourceGenerators · bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions