Don't render pure error types in OverrideMemberChooserObject

#KT-34379 Fixed
This commit is contained in:
Vladimir Dolzhenko
2019-10-16 12:16:12 +02:00
parent 148a6bd54d
commit 30229da95a
8 changed files with 43 additions and 19 deletions
@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
import org.jetbrains.kotlin.utils.checkWithAttachment
@JvmOverloads
fun KtPsiFactory(project: Project?, markGenerated: Boolean = true): KtPsiFactory = KtPsiFactory(project!!, markGenerated)
@@ -299,7 +301,12 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
fun <TDeclaration : KtDeclaration> createDeclaration(text: String): TDeclaration {
val file = createFile(text)
val declarations = file.declarations
assert(declarations.size == 1) { "${declarations.size} declarations in $text" }
checkWithAttachment(declarations.size == 1, { "unexpected ${declarations.size} declarations" }) {
it.withAttachment("text.kt", text)
for (d in declarations.withIndex()) {
it.withAttachment("declaration${d.index}.kt", d.value.text)
}
}
@Suppress("UNCHECKED_CAST")
return declarations.first() as TDeclaration
}
@@ -26,3 +26,11 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac
return this
}
}
inline fun checkWithAttachment(value: Boolean, lazyMessage: () -> String, attachments: (KotlinExceptionWithAttachments) -> Unit = {}) {
if (!value) {
val e = KotlinExceptionWithAttachments(lazyMessage())
attachments(e)
throw e
}
}
@@ -251,6 +251,7 @@ interface DescriptorRendererOptions {
var parameterNamesInFunctionalTypes: Boolean
var renderFunctionContracts: Boolean
var presentableUnresolvedTypes: Boolean
var informativeErrorType: Boolean
}
object ExcludedTypeAnnotations {
@@ -244,7 +244,11 @@ internal class DescriptorRendererImpl(
if (type is UnresolvedType && presentableUnresolvedTypes) {
append(type.presentableName)
} else {
append(type.constructor.toString()) // Debug name of an error type is more informative
if (type is ErrorType && !informativeErrorType) {
append(type.presentableName)
} else {
append(type.constructor.toString()) // Debug name of an error type is more informative
}
}
append(renderTypeArguments(type.arguments))
} else {
@@ -127,4 +127,6 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
override var presentableUnresolvedTypes: Boolean by property(false)
override var boldOnlyForNamesInHtml: Boolean by property(false)
override var informativeErrorType: Boolean by property(true)
}
@@ -22,10 +22,11 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.refinement.TypeRefinement
open class ErrorType @JvmOverloads internal constructor(
override val constructor: TypeConstructor,
override val memberScope: MemberScope,
override val arguments: List<TypeProjection> = emptyList(),
override val isMarkedNullable: Boolean = false
override val constructor: TypeConstructor,
override val memberScope: MemberScope,
override val arguments: List<TypeProjection> = emptyList(),
override val isMarkedNullable: Boolean = false,
open val presentableName: String = "???"
) : SimpleType() {
override val annotations: Annotations
get() = Annotations.EMPTY
@@ -43,14 +44,14 @@ open class ErrorType @JvmOverloads internal constructor(
}
class UnresolvedType(
val presentableName: String,
constructor: TypeConstructor,
memberScope: MemberScope,
arguments: List<TypeProjection>,
isMarkedNullable: Boolean
override val presentableName: String,
constructor: TypeConstructor,
memberScope: MemberScope,
arguments: List<TypeProjection>,
isMarkedNullable: Boolean
) : ErrorType(constructor, memberScope, arguments, isMarkedNullable) {
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
UnresolvedType(presentableName, constructor, memberScope, arguments, newNullability)
UnresolvedType(presentableName, constructor, memberScope, arguments, newNullability)
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
import org.jetbrains.kotlin.utils.checkWithAttachment
import kotlin.math.min
class ToFromOriginalFileMapper private constructor(
@@ -49,12 +49,11 @@ class ToFromOriginalFileMapper private constructor(
val syntheticText = syntheticFile.text
val originalSubSequence = originalText.subSequence(0, completionOffset)
val syntheticSubSequence = syntheticText.subSequence(0, completionOffset)
if (originalSubSequence != syntheticSubSequence) {
throw KotlinExceptionWithAttachments(
"original subText [len: ${originalSubSequence.length}]" +
" does not match synthetic subText [len: ${syntheticSubSequence.length}]"
)
.withAttachment("original subText", originalSubSequence.toString())
checkWithAttachment(originalSubSequence == syntheticSubSequence, {
"original subText [len: ${originalSubSequence.length}]" +
" does not match synthetic subText [len: ${syntheticSubSequence.length}]"
}) {
it.withAttachment("original subText", originalSubSequence.toString())
.withAttachment("synthetic subText", syntheticSubSequence.toString())
}
@@ -223,8 +223,10 @@ private val OVERRIDE_RENDERER = withOptions {
it.type.constructor.declarationDescriptor?.annotations?.hasAnnotation(ExperimentalUsageChecker.EXPERIMENTAL_FQ_NAME) ?: false
}
presentableUnresolvedTypes = true
informativeErrorType = false
}
private val EXPECT_RENDERER = OVERRIDE_RENDERER.withOptions {
modifiers = setOf(VISIBILITY, MODALITY, OVERRIDE, INNER, MEMBER_KIND)
renderConstructorKeyword = false