Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

K2: a secondary constructor's body is never converted

Chiusa
#174 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

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
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, kotlin
Ambito
compilers

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CodeLaser/maddi

Tutte le issue di CodeLaser/maddi

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.