K2: a secondary constructor's body is never converted
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start in KotlinScan.finalizeType, where each constructor body is assembled as delegation call, parameter-property assignments, then planned init blocks, and look at how runsInitOf decides which constructor runs the init blocks. Then in maddi-kotlin-k2 find where the primary constructor's body is converted and mirror it for KtSecondaryConstructor.bodyBlockExpression, appending it after the current prefix. ConstructorParameterNamedAsPropertyTest deliberately avoids a secondary constructor with a body, so extend it (or add a sibling test) with the snippet from the issue and check that n reads as assigned. Done means a secondary constructor's own body statements appear in the CST after the delegation call and init blocks.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The K2 front-end never converts a secondary constructor's block body. Given
class Secondary {
val n: Int
constructor(n: Int) { this.n = n + 1 }
}
the constructor's CST body is empty. KotlinScan.finalizeType builds every constructor body as: the explicit this(..)/super(..) invocation, then the parameter-property assignments, then the init blocks planned for it. Nothing in maddi-kotlin-k2 reads KtSecondaryConstructor.bodyBlockExpression. Only the delegation call of a secondary constructor survives.
Consequence: the body's assignments, calls and modifications are invisible to the analysis. Above, n is never assigned. A field assigned only there looks unassigned, and a parameter modified only there looks unmodified. That is the unsafe direction.
What kotlinc does: a secondary constructor runs its delegation call; when that is super(..) (or implicit), it then runs the property initializers and init blocks. Its own body comes last. A body converted after the current prefix and planned init blocks matches that order (runsInitOf already picks the constructor that runs the init blocks).
Found while fixing the same-name parameter assignment (CodeLaser/maddi-mod#73). ConstructorParameterNamedAsPropertyTest avoids a secondary constructor with a body for that reason.
- Lingua principale
- Java
- Stelle
- 1
- Fork
- 1
- Merge medio
- 1h 55m
- PR unite (30g)
- 8
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la 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 CodeLaser/maddi
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
CodeLaser/maddi#166 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
build/ci good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
front-end:rust
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
CodeLaser/maddi#165 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di CodeLaser/maddi
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
build
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
MetricsHub/metricshub-community#1472 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsExceptionForse già presa @jiteshkhatri11 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
javapathfinder/jpf-core#660 · 1 commento ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno