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
{{ message }}
Repository navigation
Drop the unused init@ field from classes with a self identifier #5284
F# adds a hidden init@<line> field to a class whose constructor has a self identifier (type P() as this or new () as self). .NET uses it to throw InvalidOperationException when this is used before the object is fully initialised. The check is a FailInit() call inside the member bodies, so M throws when called from P's constructor:
typeP()as this =letx= this.M()member_.M()=1member_.X= x
Fable emits the field and sets it, but never reads it. The typed tree Fable gets from FCS doesn't contain the FailInit() check, so there is nothing to translate. On JS:
Python emits the same shape (self.init_004039 = init_004039).
Since Fable can't use the field, we could drop it from the output: the class fields, the constructor parameter, the argument in the record construction and the Set. That saves a property per object and a write per construction.
Something to check when doing it: #5235 uses the init@ field of a precompiled class to detect that its constructor has a self identifier, because precompiled libraries don't keep constructor bodies. Removing it from the Fable AST must not remove that signal.
Activity