Created
December 7, 2013 01:45
-
-
Save ranma42/7836312 to your computer and use it in GitHub Desktop.
Test for inline functions which try to access properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace InlineTest | |
module Types = | |
type IFace = | |
abstract member Prop : obj | |
type IFace1 = | |
inherit IFace | |
abstract member Prop : int | |
type Impl() = | |
interface IFace1 with | |
member x.Prop = 1 | |
member x.Prop = "hello" :> obj | |
module Inlines = | |
let inline prop value = (^T : (member Prop : 'U) value) | |
let inline propi value = (prop value) : int | |
let inline propo value = (prop value) : obj | |
open Types | |
open Inlines | |
module Main = | |
[<EntryPoint>] | |
let main args = | |
let o = Impl() | |
let iface = o :> IFace | |
let iface1 = o :> IFace1 | |
// Using direct property access | |
// printfn "%A" (iface1.Prop : obj) // --- does not compile | |
printfn "%A" (iface.Prop : obj) // hello | |
printfn "%A" (iface1.Prop : int) // 1 | |
// printfn "%A" (iface.Prop : int) // --- does not compile | |
// Using inline property access | |
// printfn "%A" (propo iface1) // --- does not compile | |
printfn "%A" (propo iface) // hello | |
// printfn "%A" (propi iface1) // *** does not compile | |
// printfn "%A" (propi iface) // --- does not compile | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment