Where is the 'indeterminate type'?
- by Daniel
I'm defining the following type extension:
type System.Reflection.MemberInfo with
member x.GetAttribute<'T when 'T :> Attribute>(required, inherit') =
match required, Attribute.GetCustomAttribute(x, typeof<'T>, inherit') with
| true, null -> invalidOp (sprintf "Missing required attribute: %s" typeof<'T>.FullName)
| _, attr -> attr :> 'T
The last match expression (attr :> 'T) gives the error:
The static coercion from Attribute to 'T involves an indeterminate type based on information prior to this program point. Static coercions are not allowed on some types. Further type annotations are needed.
I've tried annotating the function return type, but got the same result. I would hate to change this to a dynamic cast. Is there a way to make the static cast work?