Run base constructor then blocks on the derived instance
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, python, typescript
- Domain
- compilers
Research direction
Read the constructor inheritance handling and the tests from the earlier #5235 branch at 2a69b6a8f; those tests identify the shapes a fix must handle. Reproduce the example on .NET and the #5235 branch, then trace how explicit constructors and base then blocks are compiled. Done means both derived classes compile and produce true and 2, while the listed edge cases remain correct.
Written by the indexing model from the issue text.
Description
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.
let saved = ResizeArray<obj>()
type Base =
val Name: string
new (name: string) as self = { Name = name } then saved.Add(box self)
type Derived =
inherit Base
val X: int
new () = { inherit Base("d"); X = 1 }
type Counter =
val mutable Count: int
new (c: int) as self = { Count = c } then self.Bump()
member this.Bump() = this.Count <- this.Count + 1
type CounterChild =
inherit Counter
val X: int
new () = { inherit Counter(1); X = 1 }
let d = 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 2a69b6a8f, and the tests from that version list the shapes a real fix has to handle.
- Dominant language
- F#
- Stars
- 3.2k
- Forks
- 335
- Avg merge
- 18h 57m
- Merged PRs (30d)
- 154
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fable-compiler/Fable
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
fable-compiler/Fable#5280 ·
Maintainers usually reply within 1 day
-
agentic-workflows automation repo-assist
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fable-compiler/Fable#4531 ·
Maintainers usually reply within 1 day
-
agentic-workflows automation repo-assist
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
fable-compiler/Fable#4522 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
fable-compiler/Fable#5281 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
fable-compiler/Fable#5279 ·
Maintainers usually reply within 1 day
All issues in fable-compiler/Fable
Similar issues
-
compiler: `void` inside a constant array or object literal throws in `PureFunctionConstant.keyOf`Openarea: compiler
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug gc sev-3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
GaloisInc/llvm-pretty#211 ·
-
crash mlir
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
llvm/llvm-project#239604 · 1 comment ·
Maintainers usually reply within 1 day
-
bug good first issue self-hosted compiler
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
AeroForger/AeroFyl#1 ·