Skip to content

Improve error reporting: Passing an argument to a function that is a result of a function call #6687

@isaacabraham

Description

@isaacabraham

Related #5475.

What

The following code gives an error message which could be improved upon.

let arg = " foo  "
printfn "%s" arg.Trim()

The current error message states:

error FS0597: Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized

Why

The actual error message contains the answer, but it is not easy to understand, especially for beginners to F# that don't understand why this is a problem. Worse still, if you put a space between arg.Trim and (), you get two different errors:

  1. The IDE will give the error: error FS0002: This function takes too many arguments, or is used in a context where a function is not expected
  2. Executing the entire expression in FSI will give the error: error FS0001: Type mismatch. Expecting a 'string -> 'a -> 'b' but given a 'string -> unit' The type ''a -> 'b' does not match the type 'unit'

How

I wouldn't propose initially looking at the second issue raised above (introducing a space) but would suggest rewording the initial message to something like this:

error FS0597: Incompatible arguments. If you are passing a value to a function, that is itself a function call, ensure that it is wrapped in parentheses. For example, consider rewriting 'foo bar()' as 'foo (bar())'.

I'm not sure under what other conditions this error is shown so it might need to be modified.

Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions