You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a record of a single element of type unit, the generated class constructor is invalid and produces a ReferenceError at run-time.
Repro code
Fable REPL samples...
type Test = {
Abc: unit
}
printfn "%A" <| { Abc = () }
produces:
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());
Notice that the constructor is missing the abc argument that it uses to initialize the field.
type Test = {
Abc: unit
Xyz: int
}
printfn "%A" <| { Abc = (); Xyz = 123 }
produces:
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));
So when another field is added to the record, the constructor is properly formed.
Related information
Latest everything (Fable 1), as observed via the REPL as well.
The text was updated successfully, but these errors were encountered:
SirUppyPancakes
changed the title
Records with single field of type unit generates broken constructor
Records with single field of type unit generate broken constructor
Sep 6, 2018
Description
When creating a record of a single element of type
unit
, the generated class constructor is invalid and produces a ReferenceError at run-time.Repro code
Fable REPL samples...
produces:
Notice that the constructor is missing the
abc
argument that it uses to initialize the field.produces:
So when another field is added to the record, the constructor is properly formed.
Related information
Latest everything (Fable 1), as observed via the REPL as well.
The text was updated successfully, but these errors were encountered: