Skip to content
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

SystemHelper.kt:1:1: Internal Error (no-unused-imports) #1040

Closed
5HT2 opened this issue Dec 28, 2020 · 6 comments · Fixed by #1044
Closed

SystemHelper.kt:1:1: Internal Error (no-unused-imports) #1040

5HT2 opened this issue Dec 28, 2020 · 6 comments · Fixed by #1044
Labels

Comments

@5HT2
Copy link

5HT2 commented Dec 28, 2020

Expected Behavior

I am not given this warning.

Observed Behavior

I am given this warning.

bot-kt % ktlint -F "src/main/kotlin/org/kamiblue/botkt/"
/home/mika/projects/bot-kt/src/main/kotlin/org/kamiblue/botkt/helpers/SystemHelper.kt:1:1: Internal Error (no-unused-imports). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, provide the source code that triggered an error) (cannot be auto-corrected)

Steps to Reproduce

My .editorconfig
Affected file: SystemHelper.kt
Run ktlint -F "src/main/kotlin/org/kamiblue/botkt/"

Your Environment

  • Version of ktlint used: 0.39.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint -F "src/main/kotlin/org/kamiblue/botkt/"
  • Version of Gradle used (if applicable): 6.7.1
  • Operating System and version: Linux strawberry 5.9.11-arch2-1 #1 SMP PREEMPT Sat, 28 Nov 2020 02:07:22 +0000 x86_64 GNU/Linux
  • Link to your project (if it's a public repository): bot-kt, building instructions in README.md
@5HT2
Copy link
Author

5HT2 commented Dec 28, 2020

Without -F I get this:

bot-kt % ktlint "src/main/kotlin/org/kamiblue/botkt/" 
/home/mika/projects/bot-kt/src/main/kotlin/org/kamiblue/botkt/helpers/SystemHelper.kt:1:1: File must end with a newline (\n)
/home/mika/projects/bot-kt/src/main/kotlin/org/kamiblue/botkt/helpers/SystemHelper.kt:16:50: Redundant "toString()" call in string template

Manually corrected, no more issues. I'm unsure why it couldn't autocorrect 1:1

@Tapchicoma
Copy link
Collaborator

Error stacktrace:

[DEBUG] Internal Error (no-unused-imports)
com.pinterest.ktlint.core.RuleExecutionException: java.lang.IllegalStateException: No operation node for DOT_QUALIFIED_EXPRESSION. Children: [CALL_EXPRESSION]
        at com.pinterest.ktlint.core.KtLint$format$2.invoke(KtLint.kt:346)
        at com.pinterest.ktlint.core.KtLint$format$2.invoke(KtLint.kt:27)
        at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:241)
        at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:27)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:225)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:239)
        at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:27)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:326)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:99)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:358)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:124)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:281)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:124)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: No operation node for DOT_QUALIFIED_EXPRESSION. Children: [CALL_EXPRESSION]
        at org.jetbrains.kotlin.psi.KtQualifiedExpression$DefaultImpls.getOperationTokenNode(KtQualifiedExpression.kt:35)
        at org.jetbrains.kotlin.psi.KtDotQualifiedExpression.getOperationTokenNode(KtDotQualifiedExpression.kt:26)
        at org.jetbrains.kotlin.psi.KtQualifiedExpression$DefaultImpls.getExpression(KtQualifiedExpression.kt:43)
        at org.jetbrains.kotlin.psi.KtQualifiedExpression$DefaultImpls.getSelectorExpression(KtQualifiedExpression.kt:32)
        at org.jetbrains.kotlin.psi.KtDotQualifiedExpression.getSelectorExpression(KtDotQualifiedExpression.kt:56)
        at com.pinterest.ktlint.ruleset.standard.NoUnusedImportsRule.parentDotQualifiedExpression(NoUnusedImportsRule.kt:177)
        at com.pinterest.ktlint.ruleset.standard.NoUnusedImportsRule.access$parentDotQualifiedExpression(NoUnusedImportsRule.kt:23)
        at com.pinterest.ktlint.ruleset.standard.NoUnusedImportsRule$visit$1.invoke(NoUnusedImportsRule.kt:100)
        at com.pinterest.ktlint.ruleset.standard.NoUnusedImportsRule$visit$1.invoke(NoUnusedImportsRule.kt:23)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:225)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:226)
        at com.pinterest.ktlint.ruleset.standard.NoUnusedImportsRule.visit(NoUnusedImportsRule.kt:87)
        at com.pinterest.ktlint.core.KtLint$format$2.invoke(KtLint.kt:333)
        ... 16 more
/tmp/SystemHelper.kt:1:1: Internal Error (no-unused-imports). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, provide the source code that triggered an error) (cannot be auto-corrected)

@Tapchicoma Tapchicoma added the bug label Dec 28, 2020
@Tapchicoma
Copy link
Collaborator

Issue is not related to the outdated Kotlin version. Still fails for me with Ktlint assembled with Kotlin 1.4.30-M1 Kotlin version.

@romtsn
Copy link
Collaborator

romtsn commented Dec 28, 2020

@Tapchicoma have you tried this on master? I thought it was fixed in 3591e61

@Tapchicoma
Copy link
Collaborator

@romtsn yes, I've tried it on master branch.

@t-kameyama
Copy link
Contributor

t-kameyama commented Dec 30, 2020

Test code to reproduce in master (780d11a)

@Test
fun test() {
    val actual = KtLint.format(
        KtLint.Params(
            text = """
                fun foo() = 1
                fun test() {
                    println("${'$'}{foo().toString()}")
                }

            """.trimIndent(),
            ruleSets = listOf(StandardRuleSetProvider().get()),
            cb = { _, _ -> }
        )
    )
    assertThat(actual).isEqualTo(
        """
        fun foo() = 1
        fun test() {
            println("${'$'}{foo()}")
        }

        """.trimIndent()
    )
}

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

Successfully merging a pull request may close this issue.

4 participants