Fable icon indicating copy to clipboard operation
Fable copied to clipboard

AttachMembers doesn't work with operators

Open texastoland opened this issue 3 years ago • 0 comments

Description

Incorrect function name is used at operator call site.

Repro code

REPL

open Fable.Core

[<AttachMembers>]
type Number =
  | Float of float
  | Int of int
  static member (+)(n1: Number, n2: Number) =
    match (n1, n2) with
    | (Float f1, Float f2) -> Float(f1 + f2)
    | (Float f, Int i) -> Float(f + float i)
    | (Int i, Float f) -> Float(float i + f)
    | (Int i1, Int i2) -> Int(i1 + i2)

Int 2 + Float 2 |> printfn "%O"

Expected

Number$.op_Addition(new Number$(1, 2), new Number$(0, 2))

Actual

Number$["+"](new Number$(1, 2), new Number$(0, 2))


export class Number$ extends Union {
    constructor(tag, ...fields) {
        super();
        this.tag = (tag | 0);
        this.fields = fields;
    }
    cases() {
        return ["Float", "Int"];
    }
    static op_Addition(n1, n2) {
        let i1, i2, f_1, i_1, f, i, f1, f2;
        const matchValue = [n1, n2];
        return (matchValue[0].tag === 1) ? ((matchValue[1].tag === 1) ? ((i1 = (matchValue[0].fields[0] | 0), (i2 = (matchValue[1].fields[0] | 0), new Number$(1, i1 + i2)))) : ((f_1 = matchValue[1].fields[0], (i_1 = (matchValue[0].fields[0] | 0), new Number$(0, i_1 + f_1))))) : ((matchValue[1].tag === 1) ? ((f = matchValue[0].fields[0], (i = (matchValue[1].fields[0] | 0), new Number$(0, f + i)))) : ((f1 = matchValue[0].fields[0], (f2 = matchValue[1].fields[0], new Number$(0, f1 + f2)))));
    }
}

(function () {
    const arg10 = Number$["+"](new Number$(1, 2), new Number$(0, 2));
    toConsole(printf("%O"))(arg10);
})();

Related information

  • REPL: 3.7.0
  • Fable: 3.7.0-beta-015

texastoland avatar Feb 16 '22 14:02 texastoland