Skip to content

Better diagnostic for calling Method(x = 0.5) when takes bool #9517

Open
@abelbraaksma

Description

@abelbraaksma

I hope this is just one of those gotcha's that I sometimes have when I stare too long at the screen. With NUnit, this doesn't compile:

let x = 0.5
Asssert.IsTrue(x = 0.5)   // FS0505
Asssert.IsFalse(x = 0.5)   // FS0505

The error:

FS0505: The member or object constructor 'IsTrue' does not take 0 argument(s). An overload was found taking 1 arguments.

However, these compile fine:

let x = 0.5
not(x = 0.5)
Assert.IsTrue(0.5 = 0.5)
Assert.IsFalse(0.4 = 0.5)
Assert.IsTrue(x <> 0.4)
Assert.IsFalse(x <> 0.5)
Assert.IsFalse((3.0 + 4.0) = result)

Expected behavior

I figured the above should not give a compile error.

Actual behavior

They raise FS0505. And it says "does not take 0 arguments", that doesn't seem right.

Known workarounds

Add an extra pair of parens.

Related information

As far as I can remember, any place that takes boolean can take a compare-operator, but apparently that isn't true for =, but only if the expression involves a variable identifier.

I have not checked other cases than the ones mentioned above, though I suspect it has something to do with the overload resolution, but that doesn't explain why it works with one operator, but not the other.

Or I'm totally missing the obvious 😆

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions