fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

mandatory invokeCode parameter in ProvidedMethod ctor senseless for statically parametrized TP methods #180

Closed dmitry-a-morozov closed 6 years ago

dmitry-a-morozov commented 6 years ago

Description

A new ProvidedTypes api is great but I wonder what is supposed to be passed as value for invokeCode https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/33fd1c0a95dd1ddfe77f12e4921b6983f72c8e62/src/ProvidedTypes.fsi#L96 parameter for statically parametrized TP methods.

Known workarounds

For now I used bogus value Unchecked.defaultof<_>

    let m = ProvidedMethod("CreateCommand", [], typeof<obj>, isStatic = true, invokeCode = Unchecked.defaultof<_>)
    m.DefineStaticParameters(staticParams, (fun methodName args ->
    ... 
dsyme commented 6 years ago

@dmitry-a-morozov Good point. Yes, right now you need a bogus value.

dsyme commented 6 years ago

@dmitry-a-morozov We should also add test cases to statically parameterized methods to the TPSDK itself

dmitry-a-morozov commented 6 years ago

@dsyme I'll try to find time to add the test cases

dsyme commented 6 years ago

@dmitry-a-morozov I'll leave this open as we should make the parameter optional I suppose

panesofglass commented 6 years ago

I’ve made some progress making it optional and could submit a PR, if that is helpful.

panesofglass commented 6 years ago

I'm guessing your use case was for an erasing TP, as my attempt to do this for a generative TP resulted in a NRE.