Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

False positive: unnecessary semicolon #703

Closed
JakeWharton opened this issue Feb 20, 2020 · 4 comments
Closed

False positive: unnecessary semicolon #703

JakeWharton opened this issue Feb 20, 2020 · 4 comments
Labels

Comments

@JakeWharton
Copy link
Contributor

val keyFactory = run {
  val random = Random(1);
  { random.nextInt() }
}

This is a minimal reproducing sample which is contrived, not the actual code.

The problem is that without the semicolon Kotlin thinks that I'm calling the Random constructor with a trailing lambda and fails to compile. Thus, the semicolon is necessary to separate the statement from the lambda (which is an implicit return value).

@Tapchicoma Tapchicoma added the bug label Feb 20, 2020
@romtsn
Copy link
Collaborator

romtsn commented May 14, 2020

Hm, I just tried to run no-semi rule over the sample, but it works just fine.

    @Test
    fun `test`() {
        assertThat(
            NoSemicolonsRule().lint(
                """
                val keyFactory = run {
                  val random = Random(1);
                  { random.nextInt() }
                }
                """.trimIndent()
            )
        ).isEmpty()
    }

Also, looks like it's explicitly handled on line 59:

private fun doesNotRequirePreSemi(nextLeaf: ASTNode?): Boolean {
if (nextLeaf is PsiWhiteSpace) {
val nextNextLeaf = nextLeaf.nextLeaf()
return (
nextNextLeaf == null || // \s+ and then eof
nextLeaf.textContains('\n') && nextNextLeaf.text != "{"
)
}
return nextLeaf == null /* eof */
}

Am I missing something, or the actual code was a bit different?

@shashachu
Copy link
Contributor

Closing until we get more information.

@romtsn
Copy link
Collaborator

romtsn commented Aug 8, 2020

@Mygod so the semicolon is necessary there, right? Mind filing a new issue?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants