-
Notifications
You must be signed in to change notification settings - Fork 789
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
Improve error reporting: Wrong cast operator (:?> instead of :>) #1127
Comments
first WIP PR: #1149 |
@isaksky Just a thought - C# does have two keywords - |
In fact here's another whole host of example cases... type IFoo = abstract member Bar : unit -> unit
type Foo() = interface IFoo with member __.Bar () = ()
let Thing : IFoo = Foo() // fails
let Thing2 : IFoo = Foo() :?> IFoo // fails
let Thing3 : #IFoo = Foo() // warning - and overrides the type signature!!
let Thing3 : IFoo = upcast(Foo()) // works!
let Thing4 : IFoo = downcast(Foo()) // doesn't work!
let Thing5 : IFoo = Foo() :> IFoo // works! |
I propose the error message to say: -
|
PR in #1149 |
Propose to use :> instead of :?> - fixes #1127 Thank you for taking care of this. Kevin
Related to #1103
What
Why
This error message is problematic for newcomers, especially ones from C#, because:
IDictionary<obj,obj>
is compatible withDictionary<obj, obj>
Possible solution
Before resorting to this error message, check if the left hand side can be statically cast to the type on the right, and if so, use a "consider using the :> operator" error message instead.
The text was updated successfully, but these errors were encountered: