Skip to content
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

"function" cannot be implicitly converted the same way "fun x" does. #7401

Open
smoothdeveloper opened this issue Aug 14, 2019 · 2 comments
Open
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Ready
Milestone

Comments

@smoothdeveloper
Copy link
Contributor

smoothdeveloper commented Aug 14, 2019

I found this case where function can't be substituted, in relation to implicit conversion to Func<,> delegate.

Repro steps

open System
let ae = new AggregateException()
    
ae.Handle(fun e ->
    match e with
    | :? OperationCanceledException -> true
    | _ -> false        
    )

ae.Handle(function
    | :? OperationCanceledException -> true
    | _ -> false        
    )

ae.Handle(
    Func<exn,bool>(
        function
        | :? OperationCanceledException -> true
        | _ -> false        
    ))

I'd expect those three calls to be the same, but the second one doesn't compile.

Actual behavior

This function takes too many arguments, or is used in a context where a function is not expected

The error seems incorrect in that particular context.

Expected behavior

Not sure, but it would make sense if it could compile the same as (fun x -> match x with ...) in that context.

If this can't be fixed in the language, the error could be detected to point user to the preferred solution.

related: #2907

@cartermp
Copy link
Contributor

cartermp commented Aug 6, 2020

Just feels like a bug to me.

@dsyme
Copy link
Contributor

dsyme commented Aug 31, 2020

Yes, this is a bug

@dsyme dsyme added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Aug 31, 2020
@cartermp cartermp added this to the Backlog milestone Sep 1, 2020
dsyme added a commit that referenced this issue Apr 4, 2022
@dsyme dsyme added Ready Area-Compiler-Checking Type checking, attributes and all aspects of logic checking and removed Area-Compiler labels Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Ready
Projects
Status: New
Development

No branches or pull requests

3 participants