Closed gusty closed 4 years ago
I just came with a way smaller repro:
type First<'t> = First of Option<'t> with
static member get_Zero () = First None : First<'t>
static member run (First a) = a : 't option
type Const<'t,'u> = Const of 't with
static member inline Return (_: 'U) = Const LanguagePrimitives.GenericZero : Const<'T,'U>
static member run (Const a) = a
let t2: int option =
Error 1
|> fun x -> (^``Applicative<'T>`` : (static member Return : ^T -> ^``Applicative<'T>``) x)
|> Const.run
|> First.run
printfn "t2"
If you exchange the trait-call line for |> Const.Return
it works, but otherwise compilation seems to break silently as the last line (the printfn) is not executed.
If you open the console of your browser you will see that an error is reported there.
In the "Console" section of the REPL, we only report calls to error/warn/log that are called with strings. If you have an uncatch exception at runtime like you does here you will see it in your browser console.
Fair enough, now can you tell me why do I have that runtime error? This code works just fine in fsi.
Looking at the javascript being generated, there is a difference right at the end:
This is the version with the trait-call:
export const t2 = (() => {
let arg00$$1;
let arg00;
const x = new Result(1, "Error", 1);
arg00 = new Const$00602(0, "Const", null);
arg00$$1 = Const$00602$$$run$$43814500(arg00);
return First$00601$$$run$$Z4DCCCC0(arg00$$1);
})();
toConsole(printf("t2"));
And this is the version replacing the trait-call with the actual call
export const t2 = (() => {
let arg00$$2;
let arg00$$1;
const arg00 = new Result(1, "Error", 1);
arg00$$1 = new Const$00602(0, "Const", First$00601$$$get_Zero());
arg00$$2 = Const$00602$$$run$$43814500(arg00$$1);
return First$00601$$$run$$Z4DCCCC0(arg00$$2);
})();
toConsole(printf("t2"));
Note that the trait-call generates new Const$00602(0, "Const", null);
instead of new Const$00602(0, "Const", First$00601$$$get_Zero());
That null
seems to be the problem.
I guess this should be reported to the Fable compiler, right?
Yes, you did right reporting the problem in Fable repository.
I am closing this issue as the bug is in Fable compiler.
Here's a standalone repro, including code from F#+
It prints the first message, and everything behind the following line doesn't seem to execute at all.