Kotlin unused return value checker

코틀린 반환값 미사용 검사

A compiler check warns when a meaningful expression result is discarded.

···
html
<div class="r2 returncheck" data-step="0"><div class="r2-head">RETURN VALUE CHECK<span class="r2-live"></span></div><div class="r2-stage"><div class="r2-code-line">calculate()</div><div class="r2-return-flow"><span>42</span><span>→</span><span class="r2-consumer">consumer</span></div><div class="r2-warning">unused result</div></div><div class="r2-foot"><span class="r2-caption"></span><span class="r2-progress"></span></div></div>
css
.r2{width:min(95vw,730px);height:min(92vh,330px);padding:clamp(9px,2.5vmin,17px);display:flex;flex-direction:column;gap:7px;border:1px solid var(--line);border-radius:13px;background:var(--surface);color:var(--fg);font:500 clamp(12px,3.4vmin,16px)/1.25 var(--font-sans,sans-serif)}.r2 *{box-sizing:border-box}.r2-head{display:flex;justify-content:space-between;align-items:center;min-height:17px;color:var(--accent);font-size:12px;font-weight:700;letter-spacing:.03em}.r2-live{height:7px;width:7px;border-radius:50%;background:var(--accent);animation:r2beat 1.1s infinite}@keyframes r2beat{50%{opacity:.25}}.r2-stage{flex:1;min-height:0;position:relative;overflow:hidden}.r2-foot{min-height:27px;display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px}.r2-caption{min-width:0}.r2-progress{flex:none;color:var(--accent);font:600 12px ui-monospace,monospace}.returncheck .r2-stage{display:grid;align-content:center;justify-items:center;gap:13px}.r2-code-line{font:600 12px ui-monospace,monospace;color:var(--fg)}.r2-return-flow{display:flex;align-items:center;gap:10px}.r2-return-flow span:first-child,.r2-consumer{padding:7px 10px;border:1px solid var(--line);border-radius:7px;background:var(--bg);font:600 12px ui-monospace,monospace;transition:transform .3s,opacity .3s}.r2-warning{padding:5px 9px;border:1px solid var(--accent-3);border-radius:6px;color:var(--accent-3);font-size:12px;opacity:0;transition:opacity .3s}.returncheck[data-step="0"] .r2-return-flow span:first-child{border-color:var(--accent);transform:translateY(-3px)}.returncheck[data-step="1"] .r2-consumer{opacity:.25}.returncheck[data-step="1"] .r2-warning{opacity:1}.returncheck[data-step="2"] .r2-consumer{border-color:var(--accent);transform:translateY(-3px)}.returncheck[data-step="2"] .r2-warning{opacity:0}
js
const root=document.querySelector('.r2'),caption=root.querySelector('.r2-caption'),progress=root.querySelector('.r2-progress'),labels=["Calculate a result","Unused value gets a warning","Consume the result"];let step=0;function advance(){root.dataset.step=String(step);caption.textContent=labels[step];progress.textContent=(step+1)+' / '+labels.length;step=(step+1)%labels.length}advance();const timer=setInterval(advance,1000);root.addEventListener('pointerdown',()=>{clearInterval(timer);advance()})

Kotlin 2.3 introduced an experimental check for discarded call or expression results. It can catch a newly created string that is neither returned nor stored.

The demo alternates between an ignored result that triggers a warning and a result passed to a consumer. Compiler options control coverage; some return values are intentionally ignorable.

When to use

Try it on APIs or projects where accidentally ignored results are likely, then review its warnings.

Open as page ↗