Open gusty opened 2 years ago
Hi @gusty! Thanks a lot for the report and providing the code to reproduce. This is interesting, when debugging the sample I can see the F# compiler does provide witnesses for resolution so Fable's own mechanism doesn't come into play here. It could be an issue with Fable when assigning the witness, but right now it looks as if FCS resolves the witness differently for .NET compilation and when creating the AST 😕
If you change the first argument in the second Delay
method to Default3
(or Default2
or Default1
) then it works.
static member inline Delay (_mthd: Default3, x: unit-> ^``Monad<'T>`` when ^``Monad<'T>`` : struct , _: Default2) = Bind.Invoke (Return.Invoke ()) x : ^``Monad<'T>``
static member inline Delay (_mthd: Default3, x: unit-> ^``Monad<'T>`` when ^``Monad<'T>`` : not struct , _: Default1) = Bind.Invoke (Return.Invoke ()) x : ^``Monad<'T>``
Thanks for the workaround and interesting trace into the overload resolution problem, however the goal of this repro was to understand why Fable returns this object value. Where is it coming from? None of these overloads would return such value.
Ah, sorry, didn't read well the description. The returned object is the lazy value, it looks like indeed is picking the wrong overload. The problem here is we haven't implemented ToString for lazy objects so you just see the default stringification for JS objects. We should fix that.
This bug is not about taking the wrong overload, which is an ongoing problem not easy to solve, but about returning a value not corresponding to any of the overloads.
I'm under the impression that overload resolution fails and then some buggy code returns a no sense value instead of a compile error.
Here's a repro
Running this prints
res is [object Object]
, but if we comment out the first overload of Delay, we getres is [5]
which is the expected result.Not sure, but it seems to be a problem when there are constraints in the overload, like
not struct
.