-
Notifications
You must be signed in to change notification settings - Fork 789
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
Better diagnostic for calling Method(x = 0.5) when takes bool #9517
Comments
Keeps getting weirder. This works: let result = ref 0.0
result := Operators.tanh 0.8
Assert.IsTrue(!result = 0.66403677026784891) But this doesn't, and gives a really weird error: let x = 0
Assert.IsTrue(x = 12) And: The error comes twice:
I should add that all this is in FSharp.Core.UnitTests, which uses a shadowing shim for the |
Because |
@Happypig375, nice observation (the workaround I mentioned in the issue, though). The other workaround is to use
I noticed that, only if I use the named argument correctly, as with
But even that error suggests nothing about the named argument being wrong. However, the F# compiler does have an error specific for this case, namely: type TryOut =
static member Works(condition: bool) = ()
module X =
x = 0
TryOut.Works(x = 0)
But if you use the wrong type with the correct name, you now get a correct error, though it's a confusing one: I think in all these cases, the FS0495 should have been thrown, except perhaps for the last case above, which could say something like This behavior appears to be like this since at least 2014 (I checked older VS), I'm surprised I only encounter it now. I'd like to suggest one or both solutions:
|
Of the options above, we should do this (improve the error rather than accept new programs based on named argument analysis) |
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:
The error:
However, these compile fine:
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 😆
The text was updated successfully, but these errors were encountered: