SwensenSoftware / unquote

Write F# unit test assertions as quoted expressions, get step-by-step failure messages for free
http://www.swensensoftware.com/unquote
Apache License 2.0
285 stars 26 forks source link

Improve decompilation of Decimal type numeric literals ("m"-suffixed) #118

Open stephen-swensen opened 8 years ago

stephen-swensen commented 8 years ago

F# > 4.0 quotes literal decimals in an odd way compared to other numeric literals such that it confuses the decompiler:

> <@ 2.3m @>;;
val it : Quotations.Expr<decimal> =
  Call (None, MakeDecimal,
      [Value (23), Value (0), Value (0), Value (false), Value (1uy)])
    {CustomAttributes = [NewTuple (Value ("DebugRange"),
          NewTuple (Value ("stdin"), Value (7), Value (3), Value (7), Value (7)))];
     Raw = ...;
     Type = System.Decimal;}
> unquote <@ 2.3m @>;;
val it : UnquotedExpression = 
23.[0, 0, false, 1uy]
2.3M
stephen-swensen commented 5 years ago

The problem is that literal decimals are captured as a call to IntrinsicFunctions.MakeDecimal which matches this pattern generally used for arrays forms: https://github.com/SwensenSoftware/unquote/blob/ba4bae832b0f5baec6acdb67f1f67e52236f8ae3/Unquote/Decompilation.fs#L130 https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/languageprimitives.intrinsicfunctions-module-%5Bfsharp%5D

We need to somehow evaluate this before decompiling, without doubling up in reduction steps.

stephen-swensen commented 3 years ago

It looks like bigint literals have some issues too with regard to reduction

> test <@ 3I = 2I @>;;

Test failed:

3I = 2I
3 = 2
false