Skip to content

Exception in LSP when hovering the beginning or ending curly braces of a class, data class or enum: java.lang.UnsupportedOperationException: Should not be called #600

@stefanpartheym

Description

@stefanpartheym

Hi,

I'm using kotlin-language-server with neovim and https://github.com/neovim/nvim-lspconfig.

Unfortunately, I always receive this annoying notification from the LSP in neovim, whenever I hover the beginning or ending curly braces of a class, data class or enum:
kotlin_language_server: -32603: Internal error.
image

I checked the logs, and this exception thrown in the LSP seems to be the source of this notification:

ERROR: Exception while analyzing expression in (1,50) in /dummy.virtual.kt

Attachments:
causeThrowable
java.lang.UnsupportedOperationException: Should not be called
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
	at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
	at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
	at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
	at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
	at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
	at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
	at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
	at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
	at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

----
expression.kt
<File name: dummy.virtual.kt, Physical: true>
<ELEMENT>class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
        return "Test output: ${input}"
    }
}</ELEMENT>
org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: Exception while analyzing expression in (1,50) in /dummy.virtual.kt
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:253)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:225)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
	at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
	at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
	at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
	at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
	at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
	at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
	at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.UnsupportedOperationException: Should not be called
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
	at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
	at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
	... 18 more
Okt. 31, 2024 11:38:11 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SCHWERWIEGEND: Internal error: org.javacs.kt.util.KotlinLSException: Error while analyzing: class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
...
}
java.util.concurrent.CompletionException: org.javacs.kt.util.KotlinLSException: Error while analyzing: class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
...
}
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: org.javacs.kt.util.KotlinLSException: Error while analyzing: class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
...
}
	at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:574)
	at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
	at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
	at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
	at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
	at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
	at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	... 3 more
Caused by: org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression in (1,50) in /dummy.virtual.kt

Attachments:
causeThrowable
java.lang.UnsupportedOperationException: Should not be called
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
	at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
	at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
	at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
	at org.javacs.kt.CompiledFile.bindingContextOf(CompiledFile.kt:51)
	at org.javacs.kt.CompiledFile.referenceAtPoint(CompiledFile.kt:76)
	at org.javacs.kt.CompiledFile.findDeclarationReference(CompiledFile.kt:193)
	at org.javacs.kt.CompiledFile.findDeclaration(CompiledFile.kt:187)
	at org.javacs.kt.highlight.DocumentHighlightKt.documentHighlightsAt(DocumentHighlight.kt:14)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:120)
	at org.javacs.kt.KotlinTextDocumentService$documentHighlight$1.invoke(KotlinTextDocumentService.kt:118)
	at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

----
expression.kt
<File name: dummy.virtual.kt, Physical: true>
<ELEMENT>class TestClass(val testValue: String) {

    fun testFunction(input: String): String {
        return "Test output: ${input}"
    }
}</ELEMENT>
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:261)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:225)
	at org.jetbrains.kotlin.util.PerformanceCounter.time(PerformanceCounter.kt:90)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:165)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:148)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:96)
	at org.javacs.kt.compiler.Compiler.compileKtExpression(Compiler.kt:563)
	... 12 more
Caused by: java.lang.UnsupportedOperationException: Should not be called
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.shouldNotBeCalled(TopLevelDescriptorProvider.kt:36)
	at org.jetbrains.kotlin.resolve.lazy.NoTopLevelDescriptorProvider.getPackageFragment(TopLevelDescriptorProvider.kt:39)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.getTopLevelDescriptorsByFqName(DeclarationResolver.kt:107)
	at org.jetbrains.kotlin.resolve.DeclarationResolver.checkRedeclarationsInPackages(DeclarationResolver.kt:86)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:216)
	at org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.processClassOrObject(LocalClassifierAnalyzer.kt:121)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:172)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorForStatements.visitClass(ExpressionTypingVisitorForStatements.java:73)
	at org.jetbrains.kotlin.psi.KtClass.accept(KtClass.kt:22)
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
	... 18 more

Minimal sample code to reproduce:

package org.example

import java.time.LocalDate

class TestClass(val testValue: String) { // LSP throws an exception, when this curly brace is hovered with cursor

    fun testFunction(input: String): String {
        return "Test output: ${input}"
    }
} // LSP throws an exception, when this curly brace is hovered with cursor

fun main() {
    val test = TestClass("test")
    println(test.testFunction("Hello World!"))
}

Is there a way to work around this?
Thanks

I know, this is a duplicate of #599, but I think mine is more detailed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions