dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.86k stars 777 forks source link

Units of Measure applied to literal bindings are ignored #6929

Open reinux opened 5 years ago

reinux commented 5 years ago

Instances of literal bindings assigned units of measure compile, but don't carry the measure.

Code to reproduce

type [<Measure>] rad
[<Literal>]
let pi = 3.14
let a = pi<rad>
let f (a:float<rad>) = a
f a

Expected behavior

Either an error on the assignment of a, or for f to accept pi

Actual behavior

Error   FS0001  This expression was expected to have type
    'float<rad>'    
but here has type
    'float' F#

Known workarounds

let a = pi*1.<rad>

Related information

dsyme commented 3 years ago

Yes the <rad> annotation in pi<rad> is being ignored when it should give an error

abelbraaksma commented 3 years ago

OR: @dsyme we could allow this, after all it makes sense to allow literal bindings to be augmented as measures just like literal values. Could add it here: https://github.com/fsharp/fslang-design/issues/496