-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
: Unit =
formatting
#77
Comments
@JLLeitschuh I believe you meant (something similar to) class PluginImpl : Plugin<Cat> {
override fun apply(target : Cat) : Unit =
target.run { doSomething(target) }
private fun doSomething(target: Cat) : String {
// Do some other complex logic...
return "Cat"
}
} (without Anyway, I'm actually surprised that
compiles fine when
doesn't (return type of
should be changed to
(feel free to reopen if I missed something) |
You may be right. Here's an example where I know the behaviour. class KotlinScriptBasePlugin : Plugin<Project> {
override fun apply(project: Project) : Unit =
project.run {
rootProject.apply<KotlinScriptRootPlugin>()
task<PrintAccessors>("kotlinDslAccessorsReport")
}
} This does not compile: class KotlinScriptBasePlugin : Plugin<Project> {
override fun apply(project: Project) =
project.run {
rootProject.apply<KotlinScriptRootPlugin>()
task<PrintAccessors>("kotlinDslAccessorsReport")
}
} This is under kotlin version I can't re-open as you're an admin on the repo and closing the issue prevents me from doing so. |
My point is - it shouldn't compile, because
won't (see my previous comment).
and
is the same (Task?). |
Huh... Interesting. class KotlinScriptBasePlugin : Plugin<Project> {
override fun apply(project: Project) : Unit =
project.task<PrintAccessors>("kotlinDslAccessorsReport")
} I think what the compiler is secretly doing is turning this: project.run {
rootProject.apply<KotlinScriptRootPlugin>()
task<PrintAccessors>("kotlinDslAccessorsReport")
} Into this: project.run {
rootProject.apply<KotlinScriptRootPlugin>()
task<PrintAccessors>("kotlinDslAccessorsReport")
return
} I would guess that this is so that you can write small lines of code like that and not have to worry about adding a As it stands this does compile: class KotlinScriptBasePlugin : Plugin<Project> {
override fun apply(project: Project) : Unit =
project.run {
rootProject.apply<KotlinScriptRootPlugin>()
task<PrintAccessors>("kotlinDslAccessorsReport")
}
} Any code formatter should have the behaviour of taking an input that compiles and returning an output that also compiles. This is not currently the behaviour of ktlint in this case. |
@JLLeitschuh fair enough |
So basically what we need to do here: make https://github.com/shyiko/ktlint/blob/master/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnitReturnRule.kt rewrite |
: Unit =
formatting
I would argue that's not the correct solution. The correct solution in my mind would be to not remove the A little bit more explicitly:
If we try to go down your route by adding |
@JLLeitschuh agreed |
Fixed in 0.9.2 (should become available through Maven Central within the next ~25min). |
If I have an interface like this in java:
If I override this in kotlin:
The compiler requires you to have the return type of
Unit
or it won't compile.The text was updated successfully, but these errors were encountered: