diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f140f90..367fa23a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Fixed - Comments respecting max line width (https://github.com/facebook/ktfmt/pull/511) +- Exception while parsing property accessor on Kotlin 2.0.20-Beta2+ (https://github.com/facebook/ktfmt/pull/513) ## [0.52] diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt index 5269de15..c55c3e08 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt @@ -29,6 +29,7 @@ import java.util.Optional import org.jetbrains.kotlin.com.intellij.psi.PsiComment import org.jetbrains.kotlin.com.intellij.psi.PsiElement import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace +import org.jetbrains.kotlin.com.intellij.psi.stubs.PsiFileStubImpl import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtAnnotatedExpression @@ -1415,15 +1416,17 @@ class KotlinInputAstVisitor( return 0 } - // Bug in Kotlin 1.9.10: KtProperyAccessor is the direct parent of the left and right paren + // Bug in Kotlin 1.9.10: KtPropertyAccessor is the direct parent of the left and right paren // elements. Also parameterList is always null for getters. As a workaround, we create our own // fake KtParameterList. + // TODO: won't need this after https://youtrack.jetbrains.com/issue/KT-70922 private fun getParameterListWithBugFixes(accessor: KtPropertyAccessor): KtParameterList? { if (accessor.bodyExpression == null && accessor.bodyBlockExpression == null) return null + val stub = accessor.stub ?: PsiFileStubImpl(accessor.containingFile) + return object : - KtParameterList( - KotlinPlaceHolderStubImpl(accessor.stub, KtStubElementTypes.VALUE_PARAMETER_LIST)) { + KtParameterList(KotlinPlaceHolderStubImpl(stub, KtStubElementTypes.VALUE_PARAMETER_LIST)) { override fun getParameters(): List { return accessor.valueParameters }