It appears that it must always be a 'downcast' attempt, e.g.

1
2
3
4
5
6
7
8
9
 

// Canvas is-a FrameworkElement
let canvas : System.Windows.Controls.Canvas = null
let elem : System.Windows.FrameworkElement = null
let x1 = (canvas :? System.Windows.FrameworkElement) // does not compile
let x2 = (elem :? System.Windows.Controls.Canvas) // compiles
let x3 = (elem :? System.Windows.FrameworkElement) // compiles with warning

seems like it always is asserting "ty :> tye". Oh, that's supposed to happen due to bullet (4.) in the spec you called out. What's the issue (other than the diagnostic being poor/confusing)? Basically the behavior I see is that you can type-test an attempted downcast (or no-cast to own-type, with warning), but you cannot type-test an upcast (which would always succeed).

By on 5/2/2010 11:29 AM ()

seems like it always is asserting "ty :> tye". Oh, that's supposed to happen due to bullet (4.) in the spec you called out. What's the issue (other than the diagnostic being poor/confusing)? Basically the behavior I see is that you can type-test an attempted downcast (or no-cast to own-type, with warning), but you cannot type-test an upcast (which would always succeed).

If it always succeed then why this is reported via error message (quite confusing)?
I'll try to clarify my point of view: according to spec's definition of coerce, behavior with own-type and with derived types should be the same (warning). Now it behavior of compiler dissent with specification: compile-time error in case of derived type.

By on 5/5/2010 8:45 AM ()

Thanks; I filed a bug about the confusing error diagnostic and the spec issue.

By on 5/5/2010 9:47 AM ()

I assumed that second point with 'coercion' should work not only in case of own type but also with derived types. According to definition of 'coerce' from spec type B should coerce to type A
type A = interface end
type B() = class interface A end
because A is contained in transitive closure of base types and interfaces of B.

so this case should fall into point 2 (with warning...)

By on 5/2/2010 11:58 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper