Kotlin printer: ?.let for null-guarded uses of a value (#140 follow-up)
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
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:letis inline, so a non-localreturnis allowed inside it, and Kotlin 2.2+ allowsbreak/continuethere 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
- 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 · 2 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
-
Java printer: a class literal in an annotation value prints by simple name, without an importApertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/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
Tutte le issue di CodeLaser/maddi
Issue simili
-
pdfium-drift
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
Stirling-Tools/JPDFium#188 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
openremote/openremote#3487 · 1 commento ·
-
Type/Bug U2
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
wso2/product-is#28675 ·
I maintainer di solito rispondono entro 1 giorno
-
a:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
apache/rocketmq-dashboard#7351 ·
I maintainer di solito rispondono entro 3 giorni