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

Kotlin printer: ?.let for null-guarded uses of a value (#140 follow-up)

Aperta
#164 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à
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
40/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, kotlin
Ambito
backend, compilers

Direzione di ricerca

Start by reading the Kotlin printer and the KotlinNullCheckShapes pattern matching mentioned in the issue, then trace how modification analysis determines whether a getter call is side-effect free. Implement the listed null-guard shapes while retaining smart casts for stable locals and parameters. Check the reported ?.let, !!, and ?. counts on langchain4j and fernflower, and confirm compile counts remain unchanged across jenkins, guava, langchain4j, fernflower, and timefold.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Follow-up of #140 (idiom scorecard: .let 0 in langchain4j's output).

Today. The Kotlin printer never emits let. A null-guarded use of a value prints as a smart cast where the value is a local or a parameter, or as !! where it is a getter call or a field, which Kotlin cannot smart-cast.

Shapes (Java → Kotlin):

Java Kotlin
x != null ? f(x) : null x?.let { f(it) }
x != null ? f(x) : d x?.let { f(it) } ?: d
if (getX() != null) use(getX()); (same pure getter) getX()?.let { use(it) }
T v = getX(); if (v != null) { … v … } (v not used after) getX()?.let { v -> … }

Why with #140's item 1. It shares the null-check pattern matching of ?./?: derived from Java's null checks (KotlinNullCheckShapes). It targets part of the !! count: the repeated nullable getter calls are about 100 of fernflower's 2,859 !! (corrected 2026-10-23, see the evaluation below; the first version called them the main source).

What decides it.

  • The getter must be the same call and side-effect free between the test and the use: the modification analysis says so; a syntactic translator cannot.
  • Not where the block returns from the enclosing function, or breaks/continues a loop. Corrected: let is inline, so a non-local return is allowed inside it, and Kotlin 2.2+ allows break/continue there too.
  • Keep the plain smart cast where the value is a stable local or parameter: if (x != null) use(x) is already idiomatic.

Measure. Counts of ?.let, !! and ?. on langchain4j and fernflower before and after; compile counts unchanged across jenkins, guava, langchain4j, fernflower and timefold.

🤖 Generated with Claude Code

Lingua principale
Java
Stelle
1
Fork
1
Merge medio
1h 34m
PR unite (30g)
7

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.