fsprojects / FSharp.UMX

F# units of measure for primitive non-numeric types
MIT License
154 stars 10 forks source link

Fix int16 #17

Closed kerams closed 4 years ago

kerams commented 4 years ago

This line appears to cause problems that I don't quite understand when tagging an int16 with % and the expected type is an alias of int16 with a measure. Perhaps it's because short supports units of measure natively?

[<Measure>]
type columnDefinitionId
type ColumnDefinitionId = int<columnDefinitionId>

[<Measure>]
type order
type Order = int16<order>

type ColumnDefinition = {
    Id: ColumnDefinitionId
    Order: Order }

let x = { Id = %1; Order = %2s }
//This expression was expected to have type  'Order'  but here has type  'int16<'u>'
eiriktsarpalis commented 4 years ago

I can't reproduce the error. Can you provide more details?

eiriktsarpalis commented 4 years ago

But yes you're right, the line you're removing shouldn't be necessary.

kerams commented 4 years ago

My bad. Have a look at this (turns out aliases aren't the problem). With the extra line this does not compile:

[<Measure>]
type columnDefinitionId

[<Measure>]
type order

type ColumnDefinition = {
    Id: int<columnDefinitionId>
    Order: int16<order> }

open FSharp.UMX

// This expression was expected to have type  'int16<order>'  but here has type 'int16<'u>' 
let x = { Id = %1; Order = %2s }

This does:

[<Measure>]
type columnDefinitionId

[<Measure>]
type order

open FSharp.UMX

type ColumnDefinition = {
    Id: int<columnDefinitionId>
    Order: int16<order> }

let x = { Id = %1; Order = %2s }

When [<MeasureAnnotatedAbbreviation>] type int16<[<Measure>] 'm> = int16 is removed, both snippets are fine.