I wonder where this error is coming from. Here is the code, and below the TP, which uses fsahrpx DSL
Update: I found a 'solution', which is to do the cast outside and construct one getter per cast. If anyone knows why this happens, or has better solution, I'd be glad to know. (limited quotation pattern in the ProvidedTypes-0.2.fs ?)
edit : my desperate failed attempts are not so interesting. the two interesting ones are Test93 for instance, or Test92. why would they be failing ?
update added the most litigious cases 90,91,92,93
module Module =
open System.Reflection
open Samples.FSharp.ProvidedTypes
open FSharpx.TypeProviders.DSL
open Microsoft.FSharp.Core.CompilerServices
type ReflectiveBuilder = static member Cast<'a> (args:obj) = args :?> 'a
static member BuildTypedCast lType (args: obj) =
typeof<ReflectiveBuilder>
.GetMethod("Cast")
.MakeGenericMethod([|lType|])
.Invoke(null, [|args|])
let bbgReference ns =
erasedType<obj> (Assembly.GetExecutingAssembly()) ns "Reference"
|> staticParameter "file"
(fun typeName (parameterValues:string) ->
let otwo = 2.0 :> obj
let dtwo = 2.0
let dotwo = otwo :?> float
let dcast = ReflectiveBuilder.BuildTypedCast typeof<float>
let getter = match otwo with
| :? double as d -> (fun args -> <@@ d @@>)
| :? string as d -> (fun args -> <@@ d @@>)
erasedType<string> (Assembly.GetExecutingAssembly()) ns typeName
|+!> ( provideProperty
"test90" //KO
(typeof<obj>)
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test91" //KO
(otwo.GetType())
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test92" //KO
(otwo.GetType())
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test93" //NO
typeof<float>
(fun args -> <@@ otwo :?> float @@>)
)
|+!> ( provideProperty
"test" //OK
typeof<float>
(fun args -> <@@ dtwo @@>)
)
|+!> ( provideProperty
"test2" //NO
typeof<float>
(fun args -> <@@ dtwo :> obj @@>)
)
|+!> ( provideProperty
"test3" //NO
typeof<float>
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test4" //NO
typeof<float>
(fun args -> <@@ otwo :?> float @@>)
)
|+!> ( provideProperty
"test5" //OK
typeof<float>
(fun args -> <@@ dotwo @@>)
)
|+!> ( provideProperty
"test6" //OK
typeof<float>
(fun args -> <@@ dotwo :> obj @@>)
)
|+!> ( provideProperty
"test7" //NO
typeof<float>
(fun args -> <@@ dcast otwo @@>)
)
|+!> ( provideProperty
"test8" //OK
typeof<float>
getter
)
|+!> (provideConstructor
[]
(fun _ -> <@@ "I will be the internal representation" @@>)))
[<TypeProvider>]
type public CustomTypeProvider(cfg:TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()
do this.AddNamespace("TEST", [bbgReference "TEST"])
[<TypeProviderAssembly>]
do()
the tests
module Program =
open System
type t = TEST.Reference<"">
let price = t().Test90
let price = t().Test91
let price = t().Test92
let price = t().Test93
let price = t().Test //OK
let price = t().Test2 //OK
let price = t().Test3 //NO OK
let price = t().Test4 //NO OK
let price = t().Test5 //OK
let price = t().Test6 //OK
let price = t().Test7 //NO OK
let price = t().Test8 //OK