Fable: Datensätze mit einem einzelnen Feld vom Typ unit generieren einen defekten Konstruktor

Erstellt am 6. Sept. 2018  ·  3Kommentare  ·  Quelle: fable-compiler/Fable

Beschreibung

Beim Erstellen eines Datensatzes eines einzelnen Elements vom Typ unit ist der generierte Klassenkonstruktor ungültig und erzeugt zur Laufzeit einen ReferenceError.

Repro-Code

Fable REPL-Beispiele...

type Test = {
    Abc: unit
}

printfn "%A" <| { Abc = () }

produziert:

import { setType } from "fable-core/Symbol";
import _Symbol from "fable-core/Symbol";
import { compareRecords, equalsRecords, Unit } from "fable-core/Util";
import { printf, toConsole } from "fable-core/String";
export class Test {
  constructor() {
    this.Abc = abc;
  }

  [_Symbol.reflection]() {
    return {
      type: "Test.Test",
      interfaces: ["FSharpRecord", "System.IEquatable", "System.IComparable"],
      properties: {
        Abc: Unit
      }
    };
  }

  Equals(other) {
    return equalsRecords(this, other);
  }

  CompareTo(other) {
    return compareRecords(this, other) | 0;
  }

}
setType("Test.Test", Test);
toConsole(printf("%A"))(new Test());

Beachten Sie, dass dem Konstruktor das abc Argument fehlt, das zum Initialisieren des Felds verwendet wird.

type Test = {
    Abc: unit
    Xyz: int
}

printfn "%A" <| { Abc = (); Xyz = 123 }

produziert:

import { setType } from "fable-core/Symbol";
import _Symbol from "fable-core/Symbol";
import { compareRecords, equalsRecords, Unit } from "fable-core/Util";
import { printf, toConsole } from "fable-core/String";
export class Test {
  constructor(abc, xyz) {
    this.Abc = abc;
    this.Xyz = xyz | 0;
  }

  [_Symbol.reflection]() {
    return {
      type: "Test.Test",
      interfaces: ["FSharpRecord", "System.IEquatable", "System.IComparable"],
      properties: {
        Abc: Unit,
        Xyz: "number"
      }
    };
  }

  Equals(other) {
    return equalsRecords(this, other);
  }

  CompareTo(other) {
    return compareRecords(this, other) | 0;
  }

}
setType("Test.Test", Test);
toConsole(printf("%A"))(new Test(null, 123));

Wenn also dem Datensatz ein weiteres Feld hinzugefügt wird, wird der Konstruktor richtig gebildet.

Zugehörige Informationen

Spätestens alles (Fable 1), wie auch über die REPL beobachtet.

Hilfreichster Kommentar

Sieht gut aus in Fable2

Hier ist eine Nachbildung davon, die funktioniert .

Konsole: {Abc = null}

Alle 3 Kommentare

Sieht gut aus in Fable2

Hier ist eine Nachbildung davon, die funktioniert .

Konsole: {Abc = null}

Vielen Dank, dass Sie @xdaDaveShaw überprüft haben! Wäre es in Ordnung, dieses Problem zu schließen, wenn es mit Fable 2 @SirUppyPancakes für Sie funktioniert?

Ja, definitiv!

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

ncave picture ncave  ·  3Kommentare

forki picture forki  ·  3Kommentare

tomcl picture tomcl  ·  4Kommentare

nozzlegear picture nozzlegear  ·  3Kommentare

krauthaufen picture krauthaufen  ·  3Kommentare