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

GetInvokeCode ends up calling a `not required` method #230

Closed 7sharp9 closed 6 years ago

7sharp9 commented 6 years ago

Description

I have a piece of quotation code where this line is invoked:

override this.MemberType = notRequired this "MemberType" this.Name

This stems from a call to: convMethodRefToTgt (m: MethodInfo)`

Repro steps

Write a quotation where there is a Expr.ForLoop that also involves Call and Let with ProvidedTypes as the callee for the quotation backing code.

Expected behavior

No exception

Actual behavior

Exception:

System.NotSupportedException: The operation 'MemberType' on item 'List`1' should not be called on provided type, member or parameter of type 'ProviderImplementation.ProvidedTypes.TypeSymbol'. Stack trace:
   at System.Environment.get_StackTrace()
   at ProviderImplementation.ProvidedTypes.Utils.notRequired[a,b](a this, String opname, String item) in /Users/dave.thomas/Documents/GitHub/schematization/paket-files/7sharp9/FSharp.TypeProviders.SDK/src/ProvidedTypes.fs:line 159
   at ProviderImplementation.ProvidedTypes.TypeSymbol.get_MemberType() in /Users/dave.thomas/Documents/GitHub/schematization/paket-files/7sharp9/FSharp.TypeProviders.SDK/src/ProvidedTypes.fs:line 7249
   at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
   at Microsoft.FSharp.Core.ReflectionAdapters.Type.GetCustomAttributes(Type this, Type attrTy, Boolean inherits)
   at Microsoft.FSharp.Reflection.Impl.tryFindSourceConstructFlagsOfType(Type typ)
   at Microsoft.FSharp.Reflection.Impl.isExceptionRepr(Type typ, BindingFlags bindingFlags)
   at Microsoft.FSharp.Reflection.Impl.getTypeOfReprType(Type typ, BindingFlags bindingFlags)
   at Microsoft.FSharp.Reflection.FSharpType.IsUnion(Type typ, FSharpOption`1 bindingFlags)
   at Microsoft.FSharp.Quotations.PatternsModule.loop@691-48(Type ty)
   at Microsoft.FSharp.Quotations.PatternsModule.checkObj(MemberInfo membInfo, FSharpExpr obj)
   at Microsoft.FSharp.Quotations.PatternsModule.mkInstanceMethodCall(FSharpExpr obj, MethodInfo minfo, FSharpList`1 args)
   at Microsoft.FSharp.Quotations.FSharpExpr.Call(FSharpExpr obj, MethodInfo methodInfo, FSharpList`1 arguments)
   ...

Known workarounds

None

I can provide a patch for this in a little while.

sergey-tihon commented 6 years ago

Could it be related to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/206 ?

7sharp9 commented 6 years ago

Possibly @sergey-tihon , its similar in that its a generic method with a provided operand, try the fix its pretty easy to apply.

I was using something like:

(fun field ->
                handlers
                |> List.fold
                    (fun acc (pos, handler) ->
                        Expr.IfThenElse(
                            samePosition field pos,
                            handler field,
                            acc))
                    (Expr.Value(())))
dsyme commented 6 years ago

This was fixed, at least the fix mentioned above is in the code