Repository navigation
Closed
Description
Given the following generative provider:
[<TypeProvider>]
type GenerativeProvider (config : TypeProviderConfig) as this =
inherit TypeProviderForNamespaces ()
let ns = "BasicProvider.Generative"
let asm = Assembly.LoadFrom(config.RuntimeAssembly)
let createTypes () =
let myType = ProvidedTypeDefinition(asm, ns, "MyType", Some typeof<obj>, IsErased=false)
let myCtor = ProvidedConstructor(parameters = [], InvokeCode= (fun args -> <@@()@@>))
let myStaticProp = ProvidedProperty("MyStaticProperty", typeof<string>, IsStatic = true, GetterCode = (fun args -> <@@ "Hello generative world" @@>))
let myProp = ProvidedProperty("MyProperty", typeof<string>, IsStatic = false, GetterCode = (fun args -> <@@ "Hello generative world" @@>))
let myStaticMethod = ProvidedMethod("MyStaticMethod", [], typeof<string>, IsStaticMethod=true, InvokeCode = (fun args -> <@@ "Hello generative world" @@>))
let myMethod = ProvidedMethod("MyMethod", [], typeof<string>, IsStaticMethod=false, InvokeCode = (fun args -> <@@ "Hello generative world" @@>))
myType.AddMember(myCtor)
myType.AddMember(myStaticProp)
myType.AddMember(myProp)
myType.AddMember(myStaticMethod)
myType.AddMember(myMethod)
[myType]
do
let types = createTypes()
let assemblyName = Path.ChangeExtension(Path.GetTempFileName(), ".dll")
let pa = ProvidedAssembly(assemblyName)
pa.AddTypes types
this.AddNamespace(ns, types )And the following consumer:
namespace test
module main =
type t = BasicProvider.Generative.MyType
type u = BasicProvider.Generative.MyType
[<EntryPoint>]
let main argv =
let tinstance = t()
let uinstance = u()
printfn "tinstance.MyProperty=%s" tinstance.MyProperty
printfn "uinstance.MyProperty=%s" uinstance.MyProperty
System.Console.ReadLine() |> ignore
0Incorrect IL is generated in the constructors for the type t. Notice below that type t is instantiated in correctly with type u.
This is also evident in the properties too:
Finally peverify confirms this too:
Warning: Method has multiple semantics. [token:0x06000003] [hr:0x80131299]
Warning: Method has multiple semantics. [token:0x06000004] [hr:0x80131299]
Error: Property has related method belonging to another type (method: 0x06000003; type: 0x02000003). [token:0x17000003] [hr:0x801312C5]
Error: Property has related method belonging to another type (method: 0x06000004; type: 0x02000003). [token:0x17000004] [hr:0x801312C5]
Heres a gist of full il output: https://gist.github.com/7sharp9/79469a0861850791c6ec
Repo can be found here: https://github.com/7sharp9/IntrinsicTypeExtensions
Metadata
Metadata
Assignees
Labels
No labels


Activity
dsyme commentedon Jan 28, 2016
Duplicate of #37?
7sharp9 commentedon Jan 28, 2016
Ah yes, sorry missed that, I came to the same conclusion that the static linker somehow needed to duplicate the ILDefs etc to avoid the same reference being used.
I came across this while checking the intrinsic type extension patch #882. I initially though I had broken it :-)
7sharp9 commentedon Jan 28, 2016
The information here may be useful anyway, closing.
dsyme commentedon Jan 28, 2016
Yes, very thorough report, will be helpful, thanks!