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

Warning only when function application is inside SynExpr.IfThenElse #10929

Closed
nojaf opened this issue Jan 22, 2021 · 5 comments
Closed

Warning only when function application is inside SynExpr.IfThenElse #10929

nojaf opened this issue Jan 22, 2021 · 5 comments

Comments

@nojaf
Copy link
Contributor

nojaf commented Jan 22, 2021

Consider the following code example:
image

let a =
  System.Text.RegularExpressions.Regex.IsMatch(
    "myInput",
    """^[a-zA-Z][a-zA-Z0-9']+$"""
   )

if System.Text.RegularExpressions.Regex.IsMatch(
    "myInput",
    """^[a-zA-Z][a-zA-Z0-9']+$"""
   ) then
  ()

I get an indentation warning when the function call is inside the if condition.
But not when it is used in a let binding body.

Expected behavior

I would expect both cases not to show any warnings.

Actual behavior

Warning for the expression inside the if/then/else

Known workarounds

Wrap the if condition inside parenthesises.

if (System.Text.RegularExpressions.Regex.IsMatch(
     "myInput",
      """^[a-zA-Z][a-zA-Z0-9']+$"""
   )) then
  ()

Related information

Provide any related information (optional):

  • Operating system: Win 10
  • .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET 5
  • Editing Tools (e.g. Visual Studio Version, Visual Studio): FCS 38.0.0

Related Fantomas bug: fsprojects/fantomas#1349

@cartermp
Copy link
Contributor

Other workaround :)

if System.Text.RegularExpressions.Regex.IsMatch(
                                                "myInput",
                                                """^[a-zA-Z][a-zA-Z0-9']+$"""
                                               ) then
  ()

I know that @dsyme has preferred these to be tracked as RFCs for some reason but it just kinda feels like a bug to me at this point.

@nojaf
Copy link
Contributor Author

nojaf commented Jan 22, 2021

Yeah, then the next lad complains that the max line length is not respected 🙃.
I can't win in these situations 😋.

Anyway, Don if this needs an RFC, please let me know.

@nojaf
Copy link
Contributor Author

nojaf commented Feb 5, 2021

This also happens in match expressions.
For example:

let b ="True"
let foo () =
    match Boolean.TryParse (
            b
          ) with
    | true, i -> Some i
    | false, _ -> failwith ""

image

@cartermp, @dsyme how do you want to see this fixed? If it should be fixed at all of course.

@dsyme
Copy link
Contributor

dsyme commented Jul 5, 2021

This relaxation should be tracked by a language suggestion, which we can consdier approved-in-principle.

@dsyme
Copy link
Contributor

dsyme commented Aug 24, 2021

Fixed in preview #11772

@dsyme dsyme closed this as completed Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants