From 86a8412b055dd7765b8e73a54e1e13ea22ed13cd Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 6 Nov 2019 10:57:58 +0300 Subject: [PATCH] Don't try loading PSI tree in IDE mode via stubs (e.g. decompiled code) Here we want getting trailing comma in order to check its correctness and then to report diagnostics. Now, note that if we have stub for some PSI element, it means that we're definitely not in the compiler as there are no stubs and we're definitely not in the current source file, because in the current file we have full PSI tree in IDE. Stubs are required, for example, for decompiled code and there is no need to report any diagnostics about trailing comma there. Also, because we don't have stubs for destructuring declarations, one check for trailing commas is left without similar guard ( see resolveLocalVariablesFromDestructuringDeclaration method) This commit fixes several IDE-tests: MultiFileJvmBasicCompletionTestGenerated.testDoNotCompleteWithConstraints MultiFileJvmBasicCompletionTestGenerated.testInImport MultiFileJvmBasicCompletionTestGenerated.testInImportedFunctionLiteralParameter MultiFileJvmBasicCompletionTestGenerated.testMoreSpecificExtensionGeneric MultiFileJvmBasicCompletionTestGenerated.testNoGenericFunDuplication MultiFileJvmBasicCompletionTestGenerated.testNotImportedExtensionFunction2 --- .../org/jetbrains/kotlin/resolve/TypeResolver.kt | 7 +++++-- .../ControlStructureTypingVisitor.java | 2 +- .../types/expressions/FunctionsTypingVisitor.kt | 15 ++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index cbb9a24c412..16c78075f4a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -290,7 +290,10 @@ class TypeResolver( val returnType = if (returnTypeRef != null) resolveType(c.noBareTypes(), returnTypeRef) else moduleDescriptor.builtIns.unitType - TrailingCommaChecker.check(type.parameterList?.trailingComma, c.trace, languageVersionSettings) + val parameterList = type.parameterList + if (parameterList?.stub == null) { + TrailingCommaChecker.check(parameterList?.trailingComma, c.trace, languageVersionSettings) + } result = type( createFunctionType( @@ -452,7 +455,7 @@ class TypeResolver( ): PossiblyBareType { val qualifierParts = qualifierResolutionResult.qualifierParts - if (element is KtUserType) { + if (element is KtUserType && element.stub == null) { TrailingCommaChecker.check(element.typeArgumentList?.trailingComma, c.trace, languageVersionSettings) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 646d2062eef..03ba45f3347 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -493,7 +493,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { public KotlinTypeInfo visitTryExpression(@NotNull KtTryExpression expression, ExpressionTypingContext typingContext) { expression.getCatchClauses().forEach((catchClause) -> { KtParameterList parameters = catchClause.getParameterList(); - if (parameters != null) { + if (parameters != null && parameters.getStub() == null) { TrailingCommaChecker.INSTANCE.check(parameters.getTrailingComma(), typingContext.trace, typingContext.languageVersionSettings); } }); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 58463f0bdf7..e0311c1497b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -143,11 +143,16 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre components.identifierChecker.checkDeclaration(it, context.trace) UnderscoreChecker.checkNamed(it, context.trace, components.languageVersionSettings, allowSingleUnderscore = true) } - TrailingCommaChecker.check( - expression.functionLiteral.valueParameterList?.trailingComma, - context.trace, - context.languageVersionSettings - ) + + val valueParameterList = expression.functionLiteral.valueParameterList + if (valueParameterList?.stub == null) { + TrailingCommaChecker.check( + valueParameterList?.trailingComma, + context.trace, + context.languageVersionSettings + ) + } + val safeReturnType = computeReturnType(expression, context, functionDescriptor, functionTypeExpected) functionDescriptor.setReturnType(safeReturnType)