Explicit constructor inheriting a class with a primary constructor drops the base
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 44/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- fsharp, javascript, python
- Ambito
- compilers
Direzione di ricerca
Start by running the issue’s F# reproduction and inspecting the generated JavaScript; compare the result with the reported Python behavior. Trace how the compiler handles explicit constructors and inherited primary-constructor arguments, using the linked #5226 context as background. Done means derived instances retain the base behavior across targets, and unsupported inheritance chains produce a compile error instead of incorrect output.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
A class written with val fields and an explicit new that inherits from a class with a primary constructor compiles to a class that does not extend the base. The base constructor is called but its result is thrown away, so inherited members read undefined and type tests against the base fail.
type Point(x: int) =
member _.X = x
type Labelled =
inherit Point
val Label: string
new (x: int, label: string) = { inherit Point(x); Label = label }
let p = Labelled(3, "origin")
printfn "X: %A, Label: %A, isPoint: %b" p.X p.Label (box p :? Point)
.NET prints X: 3, Label: "origin", isPoint: true. Fable JS prints X: 0, Label: "origin", isPoint: false. Python behaves the same way.
Generated JS:
export class Labelled {
constructor(Label) {
this.Label = Label;
}
}
export function Labelled_$ctor_Z176EF219(x, label) {
Point_$ctor_Z524259A4(x);
return new Labelled(label);
}
This is the case #5226 left out. That PR fixed #2425 for the situation where every class in the chain uses val fields: the generated constructor of the derived class takes the inherited fields and the explicit constructor copies them from an instance built by the base's own constructor function. That does not work here because Point's JS constructor takes its constructor arguments, not its fields, so there is nothing to copy from. The fix probably has to pass the inherit Point(x) arguments straight through to super(...), which also means a val class two levels below a primary-constructor class cannot be supported that way and should get a compile error rather than silent wrong output.
- Lingua principale
- F#
- Stelle
- 3.2k
- Fork
- 335
- Merge medio
- 18h 11m
- PR unite (30g)
- 152
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fable-compiler/Fable
-
agentic-workflows automation repo-assist
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
fable-compiler/Fable#4531 ·
I maintainer di solito rispondono entro 1 giorno
-
agentic-workflows automation repo-assist
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
fable-compiler/Fable#4522 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
fable-compiler/Fable#5257 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
fable-compiler/Fable#5253 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
fable-compiler/Fable#5229 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di fable-compiler/Fable
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 87/100
gleam-lang/gleam#6491 ·
I maintainer di solito rispondono entro 1 giorno
-
clang:frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
llvm/llvm-project#238916 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
C ABI signature lowering drops explicit function alignmentForse già presa @cpunion l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug Fortran low priority OOP
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100