Improve error reporting: Warn when pipe operators are incorrectly indented #1442
Labels
Feature Improvement
Theme-Simple-F#
A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone
What
Another one for the #1103 list. A recent F# question on StackOverflow highlighted a place where the compiler's error messages are not helpful. The user wrote the following code:
Note that the user's original code used the verbose-syntax usage of
let ... in
here, which I've replaced with light-syntaxlet
(withoutin
) since the syntax makes no difference in this case and the same unhelpful compiler errors appear.This function produces two error messages: one on the
let
oflet (result, _) = ...
, and one on the||>
operator. The error onlet
is:and the error on the
||>
is:Why
The StackOverflow user asking this question appeared to understand F# pretty well, but he was not able to figure out from those two error messages that he had an indentation problem with his pipe operator. It should have been indented far enough to be under the
((default_settings, "-f"), argv)
tuple, but the error messages onlet
and||>
give no clue to that fact.How
The code pattern of
let something = somethingElse |> someFunc
is extremely common. If the|>
operator (or any other pipe operator like||>
,<|
, and so on) is found "alone" on a line when the previous line had alet
statement, it's likely that the user meant to indent the|>
to line up withsomethingElse
. So a nicer error message for the original user's code might have been:With, of course, the actual operator in the sentence "The
||>
operator should be indented ...". This will usually be the|>
operator, since||>
has very few good use cases outside of piping into a.fold
-- but the same error message should be applicable to all the piping operators.The text was updated successfully, but these errors were encountered: