Incorrect syntax highlighting for F# code

Issue #16550 new
Robin Munn created an issue

The F# language lets you treat any operator as a function by enclosing it in parentheses; this allows you to add the items of a list by using List.reduce (+). (Of course, List.sum already exists for this purpose). However, when that operator is the multiplication operator *, the syntax highlighting in the source browser mistakes the (* sequence for the opening of a multi-line comment (which in F# is enclosed between (* and *) and can be nested). There's a special rule in the F# parser that says that the sequence (*) is not a comment-opener followed by a right parenthesis, but is instead the multiplication operator between parentheses.

To demonstrate of the issue, here are two lines of code that multiply all the items of a list together and print its output.

let product lst = lst |> List.reduce (*)
printfn "%d" (product [1; 2; 3; 4; 5])  // Prints 120

When I preview this code in the issue tracker, the syntax highlighting in the issue tracker gets it right: the second line is not highlighted as a comment. But if you look at the same source code in a file in the source browser, the highlighting is wrong, and it shows the second line as a comment.

Screenshot showing correct highlighting in issue tracker:


Screenshot showing incorrect highlighting in source browser:


Comments (0)

  1. Log in to comment