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
This commit is contained in:
Mikhail Zarechenskiy
2019-11-06 10:57:58 +03:00
parent aff9ae2ecf
commit 86a8412b05
3 changed files with 16 additions and 8 deletions
@@ -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)
}
@@ -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);
}
});
@@ -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)