Skip to content

Commit

Permalink
Improved nice print to give literal values (dotnet#10398)
Browse files Browse the repository at this point in the history
* Improved nice print to give literal values

* Addressed CR
  • Loading branch information
En3Tho authored and nosami committed Feb 22, 2021
1 parent aa840a8 commit edac855
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,29 @@ module private PrintTastMemberOrVals =
let prettyLayoutOfMemberNoInstShort denv v =
prettyLayoutOfMemberShortOption denv emptyTyparInst v true |> snd

let layoutOfLiteralValue literalValue =
let literalValue =
match literalValue with
| Const.Bool value -> if value then WordL.keywordTrue else WordL.keywordFalse
| Const.SByte _
| Const.Byte _
| Const.Int16 _
| Const.UInt16 _
| Const.Int32 _
| Const.UInt32 _
| Const.Int64 _
| Const.UInt64 _
| Const.IntPtr _
| Const.UIntPtr _
| Const.Single _
| Const.Double _
| Const.Decimal _ -> literalValue.ToString() |> tagNumericLiteral |> wordL
| Const.Char _
| Const.String _ -> literalValue.ToString() |> tagStringLiteral |> wordL
| Const.Unit
| Const.Zero -> literalValue.ToString() |> tagText |> wordL
WordL.equals ++ literalValue

let private layoutNonMemberVal denv (tps, v: Val, tau, cxs) =
let env = SimplifyTypes.CollectInfo true [tau] cxs
let cxs = env.postfixConstraints
Expand Down Expand Up @@ -1328,9 +1351,13 @@ module private PrintTastMemberOrVals =
layoutTyparDecls denv nameL true tps
else nameL
let valAndTypeL = (WordL.keywordVal ^^ typarBindingsL --- wordL (tagPunctuation ":")) --- layoutTopType denv env argInfos rty cxs
match denv.generatedValueLayout v with
| None -> valAndTypeL
| Some rhsL -> (valAndTypeL ++ wordL (tagPunctuation"=")) --- rhsL
let valAndTypeL =
match denv.generatedValueLayout v with
| None -> valAndTypeL
| Some rhsL -> (valAndTypeL ++ wordL (tagPunctuation"=")) --- rhsL
match v.LiteralValue with
| Some literalValue -> valAndTypeL ++ layoutOfLiteralValue literalValue
| None -> valAndTypeL

let prettyLayoutOfValOrMember denv typarInst (v: Val) =
let prettyTyparInst, vL =
Expand Down

0 comments on commit edac855

Please sign in to comment.