Error when using SI Unit Symbols and ProvidedMeasureBuilder
Description
When annotating properties/fields with the ProvidedMeasureBuilder.SI method, unit symbols cause an error: [type provider] reported an error: not an array, pointer, or byref type.
This seems to occur because the unit symbol types actually point to the unit name type. For example, the following is defined in SI.fs:
[<Measure>]
/// The SI unit of length
type metre
[<Measure>]
/// The SI unit of length
type meter = metre
[<Measure>]
/// A synonym for Metre, the SI unit of length
type m = metre
The following will work fine:
ProvidedMeasureBuilder.SI "metre"
However, either of these will result in the above error:
ProvidedMeasureBuilder.SI "meter"
ProvidedMeasureBuilder.SI "m"
It look like type names list https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L1247-L1260
out of sync with types from Microsoft.FSharp.Data.UnitSystems.SI namespace
https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/SI.fs
@martinjoshua Do you want to contribute back the fix? It should as easy as:
- Update the hardcoded lists in local version of
ProvidedTypes.fs - Compile TP using local new
ProvidedTypes.fsand ensure that new names and abbreviation works - Create PR to this repo with the fix
- Add new test that cover new unit of measure names (ideally)
@sergey-tihon although I'd be happy to help, I really don't think that is the issue here. The units "meter" and "m" are clearly both defined in the list, yet they still result in the above error. I wonder if this has something to do with it being generated types and not erased.
@sergey-tihon although I'd be happy to help, I really don't think that is the issue here. The units "meter" and "m" are clearly both defined in the list, yet they still result in the above error. I wonder if this has something to do with it being generated types and not erased.
These are abbreviations, which do not work. You must use the canonical non-abbreviated name from FSharp.Data.UnitSystems.SI.UnitNames
Looks like this can be closed.