-
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
Bugfix for DotLambda - (a, (b, c)) was incorrectly detected as a discard (a compiler generated one was there) #16334
Bugfix for DotLambda - (a, (b, c)) was incorrectly detected as a discard (a compiler generated one was there) #16334
Conversation
I wonder what is the rationale to disallow these lambdas in some of the cases? For example, these cases are allowed: let getP =
let _ = () // this `_` is definitely in scope but is ignored
[""] |> List.map _.Length let getP x : (string -> int) =
match x with
| null -> failwith ""
| _ -> _.Length // this is allowed, despite the another `_` in the scope type T() =
member _.M() =
[""] |> List.map _.Length There are probably more, these are just from the top of my head. let f a b _ =
// many lines of (nested) code
let x =
// many lines of code
xs |> Seq.map _.P // not allowed because of `_` somewhere else above (i.e. in `f`) I think it should be consistent: we should either disallow it everywhere where |
Important: This is just a warning hinting that readers of the code might think the code is doing something with "the other underscore". It is not a hard error. |
That's an important note, I agree. However, a lot of people use settings like |
TBH I have no problem with changing that warning into being an optional one. @vzarytovskii : Can we change an existing warning into optional one after net8 has been released? |
We can, since it shouldn't break any existing code. |
Fixes #16276 .
This change makes sure that only real "_" discards produce a warning.
Hidden compiler-generated discards that cover a different construct (e.g. a discard for a tuple which is not reference as a whole) are not going to produce a warning for ambiguity.
At the same time, this also changes the warning to be an optional one.