-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Some escapes are unexpectedly modified in character literal patterns #1372
Comments
Hello @vain0x, thank you for reporting this issue and showing interest in the project. The nature of this problem is that the AST does not represent anymore what the user originally typed. ImplFile
(ParsedImplFileInput
("tmp.fsx", true, QualifiedNameOfFile Tmp$fsx, [], [],
[SynModuleOrNamespace
([Tmp], false, AnonModule,
[DoExpr
(NoDebugPointAtDoBinding,
Match
(DebugPointAtBinding tmp.fsx (1,0--1,17) IsSynthetic=false,
App
(NonAtomic, false, Ident char,
Const (Int32 0, tmp.fsx (1,11--1,12) IsSynthetic=false),
tmp.fsx (1,6--1,12) IsSynthetic=false),
[Clause
(Or
(Or
(Or
(Or
(Const
(Char '\'',
tmp.fsx (2,2--2,6) IsSynthetic=false),
Const
(Char '"',
tmp.fsx (3,2--3,6) IsSynthetic=false),
tmp.fsx (2,2--3,6) IsSynthetic=false),
Const
(Char '\000',
tmp.fsx (4,2--4,8) IsSynthetic=false),
tmp.fsx (2,2--4,8) IsSynthetic=false),
Const
(Char '\000', tmp.fsx (5,2--5,10) IsSynthetic=false),
tmp.fsx (2,2--5,10) IsSynthetic=false),
Wild tmp.fsx (6,2--6,3) IsSynthetic=false,
tmp.fsx (2,2--6,3) IsSynthetic=false), None,
Const (Unit, tmp.fsx (6,7--6,9) IsSynthetic=false),
tmp.fsx (2,2--6,3) IsSynthetic=false, Yes)],
tmp.fsx (1,0--6,9) IsSynthetic=false),
tmp.fsx (1,0--6,9) IsSynthetic=false)], PreXmlDocEmpty, [], None,
tmp.fsx (1,0--7,0) IsSynthetic=false)], (true, true))) Notice the last two For now, we can work around this with trivia. (capturing the original char contents via the F# tokens). We have a helper to detect the char content of the trivia: fantomas/src/Fantomas/CodePrinter.fs Line 4981 in b36e5a5
This helper needs a fix, please move let ``get CharContent`` range (nodes: Map<FsAstType, TriviaNode list>) =
getNodesForTypes
[ SynExpr_Const
SynPat_Const ]
nodes
|> List.tryFind (fun tv -> RangeHelpers.rangeEq tv.Range range)
|> Option.bind
(fun tv ->
match tv.ContentItself with
| Some (CharContent c) -> Some c
| _ -> None) This will solve the problem I believe. |
Thanks for help! |
Thanks for your first contribution to this project! |
Issue created from fantomas-online
Code
Result
Problem description
In character literal patterns, hex escape sequences, unicode escape sequences and single/double quote escape sequences are modified (unescaped). Expected behavior is that these literals are kept unchanged.
Extra information
Options
Fantomas Master at 01/17/2021 13:01:42 - b36e5a5
Default Fantomas configuration
Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?
The text was updated successfully, but these errors were encountered: