NoEagerConstraintApplicationAttribute Type

Adding this attribute to the method adjusts the processing of some generic methods during overload resolution.

During overload resolution, caller arguments are matched with called arguments to extract type information. By default, when the caller argument type is unconstrained (for example a simple value x without known type information), and a method qualifies for lambda constraint propagation, then member trait constraints from a method overload are eagerly applied to the caller argument type. This causes that overload to be preferred, regardless of other method overload resolution rules. Using this attribute suppresses this behaviour.


Consider the following overloads:

 type OverloadsWithSrtp() =
     static member inline SomeMethod< ^T when ^T : (member Number: int) > (x: ^T, f: ^T -> int) = 1
     static member SomeMethod(x: 'T list, f: 'T list -> int) = 2
 let inline f x = 
     OverloadsWithSrtp.SomeMethod (x, (fun a -> 1))
With the attribute, the overload resolution fails, because both members are applicable. Without the attribute, the overload resolution succeeds, because the member constraint is eagerly applied, making the second member non-applicable.


Constructor Description


Full Usage: NoEagerConstraintApplicationAttribute()

Returns: NoEagerConstraintApplicationAttribute NoEagerConstraintApplicationAttribute

Creates an instance of the attribute

Returns: NoEagerConstraintApplicationAttribute