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
Run base constructor then blocks on the derived instance #5272
On JS, TS and Python, Fable can't inherit from a class whose explicit constructor has a self identifier, and a class with a base class can't have one. Once #5235 merges, both are compile errors, as they are on main. .NET prints true and 2.
letsaved= ResizeArray<obj>()typeBase=valName:stringnew(name:string)as self ={ Name = name }then saved.Add(box self)typeDerived=inherit Base
valX:intnew()={inherit Base("d"); X =1}typeCounter=val mutableCount:intnew(c:int)as self ={ Count = c }then self.Bump()memberthis.Bump()= this.Count <- this.Count +1typeCounterChild=inherit Counter
valX:intnew()={inherit Counter(1); X =1}letd= Derived()
printfn "%b"(obj.ReferenceEquals(saved.[0], d))
printfn "%d"(CounterChild()).Count
On the #5235 branch, both derived classes fail with:
error FABLE: Program.Base has a constructor with a self identifier (`new() as x`), which Fable does not support inheriting from.
Both programs are valid F#. Supporting them means running the base then block on the derived instance. One idea, untested, is to split explicit constructors into separate allocate and initialize steps.
An earlier version of #5235 built a separate base object and copied its fields into the derived one. That was dropped because it gave wrong output for: curried function fields in the derived class, a base behind a .fsi, an [<AttachMembers>] base, and leaking self. It's in the branch history at 2a69b6a, and the tests from that version list the shapes a real fix has to handle.
Activity