Skip to content

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

Closed

Description

@nojaf

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

Activity

  1. cartermp commented on Jan 22, 2021

    @cartermp
    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.

  2. nojaf commented on Jan 22, 2021

    @nojaf
    ContributorAuthor

    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.

  3. nojaf commented on Feb 5, 2021

    @nojaf
    ContributorAuthor

    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.

  4. added this to the Backlog milestone on Feb 6, 2021
  5. dsyme commented on Jul 5, 2021

    @dsyme
    Contributor

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

  6. dsyme commented on Aug 24, 2021

    @dsyme
    Contributor

    Fixed in preview #11772

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions