Fable: تؤدي السجلات ذات الحقل الفردي لوحدة النوع إلى إنشاء مُنشئ معطل

تم إنشاؤها على ٦ سبتمبر ٢٠١٨  ·  3تعليقات  ·  مصدر: fable-compiler/Fable

وصف

عند إنشاء سجل لعنصر واحد من النوع unit ، فإن مُنشئ الفئة المُنشأ غير صالح وينتج خطأ ReferenceError في وقت التشغيل.

رمز Repro

عينات REPL الخرافة ...

type Test = {
    Abc: unit
}

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

ينتج عنه:

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());

لاحظ أن المُنشئ يفتقد الوسيطة abc التي تستخدمها لتهيئة الحقل.

type Test = {
    Abc: unit
    Xyz: int
}

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

ينتج عنه:

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));

لذلك عند إضافة حقل آخر إلى السجل ، يتم تكوين المُنشئ بشكل صحيح.

معلومات ذات صله

أحدث كل شيء (خرافة 1) ، كما لوحظ عبر REPL أيضًا.

التعليق الأكثر فائدة

تبدو جيدة في الخرافة 2

هنا بديل له يعمل .

وحدة التحكم: {Abc = null}

ال 3 كومينتر

تبدو جيدة في الخرافة 2

هنا بديل له يعمل .

وحدة التحكم: {Abc = null}

شكرا للتحقق منxdaDaveShaw! هل سيكون من المقبول إغلاق هذه المشكلة إذا كانت تعمل من أجلك مع Fable 2SirUppyPancakes؟

نعم بالتأكيد!

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات