Skip to content

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

@smoothdeveloper

Description

@smoothdeveloper

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

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.Ready

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions