Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved nice print to give literal values #10398

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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