fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Error when using SI Unit Symbols and ProvidedMeasureBuilder #269

Closed martinjoshua closed 1 year ago

martinjoshua commented 5 years ago

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"
sergey-tihon commented 5 years ago

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:

  1. Update the hardcoded lists in local version of ProvidedTypes.fs
  2. Compile TP using local new ProvidedTypes.fs and ensure that new names and abbreviation works
  3. Create PR to this repo with the fix
  4. Add new test that cover new unit of measure names (ideally)
martinjoshua commented 5 years ago

@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.

dsyme commented 5 years ago

@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

kevmal commented 1 year ago

Looks like this can be closed.