[KOTLIN] "Declaration has type inferred from a platform call (...)" warning for "void" call combined with expression syntax

已回答

Hello!

Intellij Idea gives the "Declaration has type inferred from a platform call, which can lead to unchecked nullability issues." warning for this code:

fun delete(id: UUID) = groupRepo.findById(id).map { groupRepo.deleteById(id) }.orElseThrow { GroupNotFoundException(id) }

but it does not for this code:

fun delete(id: UUID) { groupRepo.findById(id).map { groupRepo.deleteById(id) }.orElseThrow { GroupNotFoundException(id) } }

(deleteById is void) Aside from the fact that the code can be improved, one might say that using the expression syntax for void type doesn't make sense, but I see it just as a syntactic sugar. Saves typing {} which is difficult because it requires reaching Shift, which is mapped to a rapid temperature spike in my setup.

Anyway, is it by design or should I report a false positive?

Cheers,
Jacek

kotlin plugin: 203-1.4.21-release-IJ6682.9

IntelliJ IDEA 2020.3.1 (Ultimate Edition)
Build #IU-203.6682.168, built on December 29, 2020
Subscription is active until July 17, 2021.
Runtime version: 11.0.9.1+11-b1145.63 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.8.0-38-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 7981M
Cores: 8
Non-Bundled Plugins: Base64 for IDEA and Storm, Batch Scripts Support, CMD Support, Dilbert, IdeaVIM, PlantUML integration, Statistic, com.alayouni.ansiHighlight, com.github.leomillon.uuidgenerator, com.intellij.apacheConfig, com.intellij.ideolog, com.jetbrains.plugins.ini4idea, com.intellij.plugins.watcher, com.khmelyuk.multirun, com.sburlyaev.terminal.plugin, de.ax.powermode, main.kotlin.com.jimschubert.intellij.swaggercodegen, net.seesharpsoft.intellij.plugins.csv, nl.jworks.intellij.bootstrap3, org.github.plugin.redis-simple, org.intellij.plugins.hcl, com.crunch42.openapi, org.sylfra.idea.plugins.linessorter, org.turbanov.run.configuration.as.action, send2terminal, GrepConsole, com.euphoricity.gitignore, com.github.syuchan1005.ImageComment, com.intellij.bigdecimal-folding, com.linsage, com.williamlee.plugin.swagger.generate, de.u-mass.idea.copyConstructor, marcglasberg.HibernateInspectionsPlugin, org.sonarlint.idea, com.deadlock.scsyntax, com.alivanov.intellij.plugins.liquigen, com.ifengxue.plugin.jpa-support, org.jetbrains.kotlin, com.bruce.intellijplugin.generatesetter, io.ktor.intellij.plugin, com.suusan2go.kotlin-fill-class, com.mistamek.drawablepreview.drawable-preview, com.moxun.plugin.s2v, org.mapstruct.intellij, com.intellij.plugins.html.instantEditing, org.mvnsearch.rest-editor-client-contrib, org.jetbrains.plugins.ruby, Pythonid, net.ashald.envfile, org.exbin.deltahex.intellij, ru.adelf.idea.dotenv, nl.rubensten.texifyidea
Current Desktop: ubuntu:GNOME

 

0

It could be a bug. Please file an issue at http://kotl.in/issue with a self-contained code sample to reproduce and investigate. Thanks!

0

请先登录再写评论。