This is not about windows forms at all it's here only for the "background".
I was toying around Windows Forms when I got an error on an AddRange
for a MenuStrip.Items
requiring to cast ToolStripMenuItem
into ToolStripItem
But I already have an AddRange
for a Form.Controls
before which didn't require casts.
After a little experimentation I managed to find that the error occurs when there are multiple overload for that AddRange
so I tried to validate my thought :
type Foo () = class end
type Bar () = inherit Foo ()
type FooCollection () = class end // not really necessary
type Test1 () =
member __.AddRange (col: FooCollection) = () // could be an int or anything instead
member __.AddRange (foos: Foo []) = ()
type Test2 () = member __.AddRange (foos: Foo []) = ()
let lst1, lst2 = Test1 (), Test2 ()
lst1.AddRange [|Bar ()|] // error: have to explicitely cast => [|Bar () :> Foo|]
lst2.AddRange [|Bar ()|] // works
The question is simply why ; from my point of view the call is not ambiguous
After reading the 14.4.3 F# spec (hinted by Gustavo, kudos to him)
The F# compiler determines whether to insert flexibility after explicit instantiation, but before any arguments are checked.
I understand that flexibility is never inserted for a method which have overloads because it would need argument checking to choose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With