Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit edac855

Browse files
En3Thonosami
authored andcommitted
Improved nice print to give literal values (dotnet#10398)
* Improved nice print to give literal values * Addressed CR
1 parent aa840a8 commit edac855

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/fsharp/NicePrint.fs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,29 @@ module private PrintTastMemberOrVals =
13011301
let prettyLayoutOfMemberNoInstShort denv v =
13021302
prettyLayoutOfMemberShortOption denv emptyTyparInst v true |> snd
13031303

1304+
let layoutOfLiteralValue literalValue =
1305+
let literalValue =
1306+
match literalValue with
1307+
| Const.Bool value -> if value then WordL.keywordTrue else WordL.keywordFalse
1308+
| Const.SByte _
1309+
| Const.Byte _
1310+
| Const.Int16 _
1311+
| Const.UInt16 _
1312+
| Const.Int32 _
1313+
| Const.UInt32 _
1314+
| Const.Int64 _
1315+
| Const.UInt64 _
1316+
| Const.IntPtr _
1317+
| Const.UIntPtr _
1318+
| Const.Single _
1319+
| Const.Double _
1320+
| Const.Decimal _ -> literalValue.ToString() |> tagNumericLiteral |> wordL
1321+
| Const.Char _
1322+
| Const.String _ -> literalValue.ToString() |> tagStringLiteral |> wordL
1323+
| Const.Unit
1324+
| Const.Zero -> literalValue.ToString() |> tagText |> wordL
1325+
WordL.equals ++ literalValue
1326+
13041327
let private layoutNonMemberVal denv (tps, v: Val, tau, cxs) =
13051328
let env = SimplifyTypes.CollectInfo true [tau] cxs
13061329
let cxs = env.postfixConstraints
@@ -1328,9 +1351,13 @@ module private PrintTastMemberOrVals =
13281351
layoutTyparDecls denv nameL true tps
13291352
else nameL
13301353
let valAndTypeL = (WordL.keywordVal ^^ typarBindingsL --- wordL (tagPunctuation ":")) --- layoutTopType denv env argInfos rty cxs
1331-
match denv.generatedValueLayout v with
1332-
| None -> valAndTypeL
1333-
| Some rhsL -> (valAndTypeL ++ wordL (tagPunctuation"=")) --- rhsL
1354+
let valAndTypeL =
1355+
match denv.generatedValueLayout v with
1356+
| None -> valAndTypeL
1357+
| Some rhsL -> (valAndTypeL ++ wordL (tagPunctuation"=")) --- rhsL
1358+
match v.LiteralValue with
1359+
| Some literalValue -> valAndTypeL ++ layoutOfLiteralValue literalValue
1360+
| None -> valAndTypeL
13341361

13351362
let prettyLayoutOfValOrMember denv typarInst (v: Val) =
13361363
let prettyTyparInst, vL =

0 commit comments

Comments
 (0)