I'm writing some extensions for the FunScript project (F# to Javascript compiler). If you're interested you can find the source here.
I was trying to emulate the AwaitObservable extension by Tomas Petricek. However, if I use overloaded methods like AwaitObservable(w), AwaitObservable(w1,w2)...
I get the following error when I try to compile a project to Javascript:
An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in FSharp.Core.dll
Additional information: Ambiguous match found.
FunScript keeps a cache dictionary of the reflected definitions in the project, and this error occurs when it tries to add a new one to the cache using Expr.TryGetReflectedDefinition
. The error disappears if I use different names instead of overloads (AwaitObservable2, AwaitObservable3...
). That's the workaround I'm using now, but I would like to know more about the problem and whether is possible to fix it so the users of the extensions can use overloaded methods normally.
I can imagine that Reflected Definitions in F# don't support overloaded methods and cannot distinguish methods just by the number of arguments (I couldn't check that because I didn't find the implementation of Expr.TryGetReflectedDefinition
in the fsharp GitHub source repository). However, what puzzles me is that the error doesn't happen when looking for AwaitObservable but the following method:
{System.IDisposable System-IObservable
1-Subscribe(System.IObserver
1[FunScript.TypeScript.MouseEvent])} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
So my questions are:
- Why is
Expr.TryGetReflectedDefinition
failing withIObservable.Subscribe
instead ofAsync.AwaitObservable
? - Why is
Expr.TryGetReflectedDefinition
throwing an exception instead of returning None? - Is this a bug of F# Reflected Definitions or an unavoidable limitation? Is it possible to fix it?
Thanks a lot in advance for your help!